Image processing PIC1.0 version

zhaozj2021-02-16  75

Package graphics;

Import java.awt. *; import java.awt.Event. *; import javax.swing. *; import java.awt.Image. *; import java.io. *; import java.awt.image. *; import java .awt *;. import java.util *;. import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.image.codec.jpeg.JPEGImageEncoder; import javax.imageio *;. public class Frame1 extends JFrame {Final Static INT R = 1; Final Static Int B = 0; FINAL Static Int Alpha = 3; JPanel ContentPane; BorderLayout BorderLayout1 = New BorderLayout (); MenuBar MenuBar1 = New MenuBar (); Menu Menu1 = new menu (); menuitem menuitem1 = new menuitem (); menu menu2 = new menu (); menuitem menuitem2 = new menuItem (); jPanetl lb = new jlabel (); jPanel pl = new jPanel (); menuitem menuitem3 = new Menuitem (); // main image path string string string = null; String Dir = null; // seal image path string string STRSEALFILE = NULL; STRING Sealdir = NULL; MENUIIIIIIIIIIIIIIIITEM4 = New MenuItem (); // Pixel Array INT Pixarray [] = null; int rarray [] [] = null; int garray [] [] = null; int Barray [] [] = null; int alparray [] [] = NULL; // Defines the pixel array of the seal image INT SealpixArray [] = null; int sealray [] [] = null; int sealgarray [] [] = null; int seealbarray [] [] = null; // main image high , Wide int h, w; // seal image is high, wide int see, Sealw;

MenuItem menuItem5 = new MenuItem (); MenuItem menuItem6 = new MenuItem (); MenuItem menuItem7 = new MenuItem (); MenuItem menuItem8 = new MenuItem (); MenuItem menuItem9 = new MenuItem (); MenuItem menuItem10 = new MenuItem (); Menu menu3 = new menu (); menuitem menuitem11 = new menuItem (); public frame1 () {enableevents (awtevent.window_event_mask; try {jbinit ();} catch (exception e) {E.PrintStackTrace ();}}

Private void jbinit () throws exception {contentpane = (jPanel) this.getContentPane (); contentpane.setLayout; this.settsize (New Dimension (400, 300)); this.SetTitle ("PIC"); Menu1. setLabel ( "File"); menuItem1.setLabel ( "open"); menuItem1.addActionListener (new Frame1_menuItem1_actionAdapter (this)); menu2.setLabel ( "Edit"); menuItem2.setLabel ( "toBandW"); menuItem2.addActionListener (new Frame1_menuItem2_actionAdapter (this)); // menuItem2.addActionListener (new Frame1_menuItem2_actionAdapter (this)); menuItem3.setLabel ( "zhifangtujunyun"); menuItem3.addActionListener (new Frame1_menuItem3_actionAdapter (this)); //menuItem3.addActionListener(new Frame1_menuItem3_actionAdapter (this) ); menuItem4.setLabel ( "RGBtoGray"); menuItem4.addActionListener (new Frame1_menuItem4_actionAdapter (this)); menuItem5.setLabel ( "linearRange"); menuItem5.addActionListener (new Frame1_menuItem5_actionAdapter (this)); menuItem6.setLabel ( "addSeal") Menuite m6.addActionListener (new Frame1_menuItem6_actionAdapter (this)); menuItem7.setLabel ( "addSeals"); menuItem7.addActionListener (new Frame1_menuItem7_actionAdapter (this)); menuItem8.setLabel ( "toHalf"); menuItem8.addActionListener (new Frame1_menuItem8_actionAdapter (this)) ; menuItem9.setLabel ( "save"); menuItem9.addActionListener (new Frame1_menuItem9_actionAdapter (this)); menuItem10.setLabel ( "exit"); menuItem10.addActionListener (new Frame1_menuItem10_actionAdapter (this)); menu3.setLabel ( "Help"); Menuitem11.SetLabel ("about");

menuItem11.addActionListener (new Frame1_menuItem11_actionAdapter (this)); menuBar1.add (menu1); menuBar1.add (menu2); menuBar1.add (menu3); menu1.add (menuItem1); menu1.add (menuItem9); menu1.add ( Menuitem10); Menu2.add (Menuitem2); menu2.add (Menuitem3); menu2.add (Menuitem4); menu2.add (menuitem6); menu2.add (Menuitem7); menu2.add (Menuitem8 ); setMenuBar (menuBar1); contentPane.add (pl, BorderLayout.CENTER); pl.add (lb); menu3.add (menuItem11);} protected void processWindowEvent (WindowEvent e) {super.processWindowEvent (e); if ( E.GetId () == windowevent.window_closing) {system.exit (0);}}

Void Menuitem1_ActionPerformed (ActionEvent E) {

FileDialog fd = new filedialog (this, "open"); fd.show (); if (fd.getfile ()! = Null) {strfile = fd.getfile (); DIR = fd.getdirectory ();} ImageICON SOURCE = New imageicon; h = source.geticonHeight (); w = source.geticonwidth (); lb.seticon (source); lb.repaint (); // Why below the code, need to RGB, ALP The array is initialized without the need to initialize Pixarray? RARRAY = new int [h]; garray = new int [h] [w]; barray = new int [h] [w]; alparray = new int [h] [w];

Pixarray = getpixarray (Dir Strfile, W, H); Rarray = GetColorarray (Pixarray, W, H, R); Garray = GetColrarray (Pixarray, W, H, G); Barray = GetColoRRay (Pixarray, W, H, B Alparray = GetColorarray (Pixarray, W, H, Alpha);

}

Void Menuitem4_ActionPerformed (ActionEvent E) {Image Im = Toolkit.getDefaultToolkit (). getImage (Dir Strfile); // INT H = Im.getHeight (NULL); // int w = im.getwidth (NULL); int [] [] graArray = new int [h] [w]; // getpixarray (dir strfile); // getrarray (Pixarray); // getGarray (Pixarray); // GetBarray (Pixarray); // GetalParray (Pixarray) Grarray = RGBTOGRAY (RARRAY, GARRAY, BARRAY, W, H); Image Pic = CreateImage (New MemoryImagesource (W, H, ArrayTransform (GrarRay, W, H), 0, W); ImageICON IC = New Imageicon (PIC ); Lb.seticon (IC); lb.repaint ();

Public static void main (string args []) {new frame1 (). show ();} public int [] [] getGrayArray (int [] [] r, int [] [] g, int [] [] B, INT W, INT H) {Int gray []; gray = new int [h] [w]; for (int i = 0; i

} Public int [] getpixarray (string path, int w, int h) {image imagers = Toolkit.getDefaultToolkit (). GetImage (path); int [] PIX = new int [w * h]; pixelgrabber pg = null; try {PG = New PixelGrabber (IM, 0, 0, W, H, PIX, 0, W); IF (pg.grabpixels ()! = True) TRY {throw new java.awt.awtexception ("pg error" pg .status ());} catch (Exception EQ) {Eq.PrintStackTrace ();}} catch (Exception ex) {EX.PRINTSTACKTRACE ();

} Return Pix;} public int [] [] getColorarray (int [] SourceArray, int W, int h, int color) {int index = 0; int [] [] array = new int [h] [w]; for (INT i = 0; i > color * 8) & 0xff; Index }} Return Array;

Public int [] LinearRay, Double A, Double B) {int [] gray = new int [grayara ".length]; for (int i = 0; i 255) Grarray [i] = 255;

} Return gray;} public int [] [] RGBTOGRAY (int [] [] r, int [] [] g, int [] [] b, int w, int h) {int [] [] gray = new int = [h]; gray = getGrayArray (R, G, B, W, H); for (int i = 0; i

Return ArrayTransform (GRAY, W, H);} // Temporation Map Metage Public Int [] ZFTJY (int [] GR) {double [] v = new double [256]; int pixel = w * h; double [] HS = new double [256]; // Calculate the number of pixels per gray level in the entire image Double [] hp = new double [256]; / / calculate the accumulated distribution of each grayscale level HP int [] gray = new int [cr.length]; // Tutorial map homogenization pixel matrix // find the grayscale histogram of the original picture F, for (int i = 0; i

}

Void Menuitem3_ActionPerformed (ActionEvent E) {int [] gray = zftjy (ArrayTransform (GetGray, Garray, Barray, W, H), W, H)); // Gray = LinearRange (Gray, 1.2, 20); for INT i = 0; i

PUBLIC INT [] ArrayTransform (int [] original, int w, int h) {int [] array = new int [w * h]; int index = 0; for (int i = 0; i

Seal [indexh] [indexwww]; indexw ;} int width = Xoffset sealw / 2; boolean sign = false; // Get circular trajectory on the seal image // Process the left INT of the seal image Int [] Tracex1 = New INT [selh]; int [] tracex2 = new int [selh];

For (int i = 0; i

Tracex1 [I] = (int) (Xoffset Sealw / 2-Math.Pow ((Math.Pow (SEALH / 2, 2) -Math.Pow (SEALH / 2-I, 2)), 0.5); TraceX2 [I] = (int) (Xoffset Sealw / 2 Math.Pow ((Math.Pow (SEALH / 2, 2) -Math.Pow (SEALH / 2-I, 2)), 0.5)); // System.out.println (TraceX [I]);} int index = 0; for (int i = yoffset; i

} For (int K = tracex2 [index]; k

Return des;} void meneuitem6_Actionperformed (ActionEvent E) {fileDialog fd = new filedialog (this, "open seal"); //fd.setFileNameFilter (New Dirfilter ()); fd.show (); if (fd.getfile () ! = null) {strSealFile = fd.getFile (); sealDir = fd.getDirectory ();} ImageIcon source = new ImageIcon (sealDir strSealFile); sealH = source.getIconHeight (); sealW = source.getIconWidth ();

Sealrarray = new int [selh] [selw]; sealgarray = new int [selh] [sealw]; seealbarray = new int [selh] [sealw];

System.out.print (SEALH ":" Sealw);

SealpixArray = GetPixArray (Sealdir strsEalfile, Sealw, Searh);

System.out.println (SealpixArray.length);

sealRArray = getColorArray (sealPixArray, sealW, sealH, R); sealGArray = getColorArray (sealPixArray, sealW, sealH, G); sealBArray = getColorArray (sealPixArray, sealW, sealH, B); int [] [] src = new int [h ] [w]; int [] [] SEL = new int [selh] [sealw]; int [] des = new int [h * w]; src = arraytransform (Pixarray, W, H); SEL = ArrayTransform (SEALPIXARRAY SEALW, SEALH; System.out.println (Sealpixarray [0]); System.out.Print (SEL [0] [0]); des = ArrayTransform (AddSeal (SRC, SEL, W, H, Sealw, Sealh , 300, 400), W, H); Image Im = CreateImage (New MemoryImagesource (W, H, DES, 0, W)); //lb.setsize (W/2 ,H/2); lb.seticon (New Imageicon (IM)); lb.repaint ();

}

void menuItem7_actionPerformed (ActionEvent e) {String [] srcFiles = null; JFileChooser fc = new JFileChooser (); fc.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY); fc.showDialog (this, "open"); System.out.print (fc. getCurrentDirectory ()); String temp = fc.getCurrentDirectory () toString ();. sort (temp);} public ArrayList getDirectory (String directory) {File file = new File (directory); if (file.isDirectory (!)) Return Null; ArrayList Files = New ArrayList (); files.add (directory); string [] _files = file.list (); string tmp = null; for (int i = 0; i <_files.length; i ) { tmp = directory "//" _ files [i]; if (getDirectory (tmp) = null!) files.addAll (getDirectory (tmp));} return files;} public void sort (String directory) {ArrayList arr = getDirectory (Directory); Object [] files = arr.toarray (); arrays.sort (files, ne W Comparator () {public int compare (object obj1, object obj2) {return ((string) Obj1) .length () - ((String) Obj2) .length ();}}); for (INT i = 0; I

Void Menuitem8_Actionperformed (ActionEvent E) {INTHH = H / 2; int WW = W / 2; int [] [] rr = new int [hh] [ww]; int [] [] gg = new int [hh] [ Ww]; int [] bb = new int [hh] [ww]; int [] pp = new int [hh * ww]; for (int i = 0; i

Void Menuitem9_ActionPerformed (ActionEvent E) {icon IC = lb.geticon (); //lb.getgraphics ().copyarea (0, 0); // imageio. //lb.getgraphics (). / * Image IMG = LB. CreateImage (w, h); graphics gr = img.getgraphics (); gr.drawimage (lb.geticon (), 0,0, null; repainTManager RM = RepaintManager.currentManager (this); lb.setBackground ); Lb.setForeground (color.blue); lb.repaint (); * / imageicon II = (imageicon) IC; image src = II.GetImage (); // image src = rm.getoffscreenbuffer (lb, w, h ); // Image src = (Image) ic; int ww = src.getWidth (null); int hh = src.getHeight (null); BufferedImage bi = new BufferedImage (ww, hh, BufferedImage.TYPE_INT_BGR); bi.getGraphics () .drawImage (src, 0,0, ww, hh, null); try {FileOutputStream out = new FileOutputStream (dir "newfile.jpg"); JPEGImageEncoder je = JPEGCodec.createJPEGEncoder (out); je.encode (bi } Catch (Exception EX) {}}}

Void Menuitem10_ActionPerformed (ActionEvent E) {//this.exi system.exit (0);

Void Menuitem11_ActionPerformed (ActionEvent E) {About AB = New About (); ab.setsize (200, 200); ab.show ();}}

Class frame1_menuitem1_actionadapter import.actionlistener {frame1 adaptee;

Frame1_menuItem1_actionAdapter (Frame1 adaptee) {this.adaptee = adaptee;} public void actionPerformed (ActionEvent e) {adaptee.menuItem1_actionPerformed (e);}} class Frame1_menuItem4_actionAdapter implements java.awt.event.ActionListener {Frame1 adaptee;

Frame1_menuitem4_actionadapter (frame1 adaptee) {this.adaptee = adaptee;} public void actionPerformed (ActionEvent E) {adaptee.Menuitem4_ActionPerformed (e);}}

class Frame1_menuItem5_actionAdapter implements java.awt.event.ActionListener {Frame1 adaptee; Frame1_menuItem5_actionAdapter (Frame1 adaptee) {this.adaptee = adaptee;} public void actionPerformed (ActionEvent e) {adaptee.menuItem5_actionPerformed (e);}}

Class frame1_menuitem2_actionadapter import.Ava.awt.event.ActionListener {Frame1 Adaptee

Frame1_menuitem2_actionadapter (frame1 adaptee) {this.adaptee = adaptee;} public void actionperformed (ActionEvent E) {adaptee.Menuitem2_ActionPerformed (e);}}

Class frame1_menuitem3_actionadapter import.Ava.awt.event.Adlistener {frame1 adaptee

Frame1_menuitem3_actionAdapter (frame1 adaptee) {this.adaptee = adaptee;} public void actionPerformed (ActionEvent E) {adaptee.Menuitem3_ActionPerformed (e);}}

Class frame1_menuitem6_actionadapter import.actionListener {frame1 adaptee;

Frame1_menuItem6_actionAdapter (Frame1 adaptee) {this.adaptee = adaptee;} public void actionPerformed (ActionEvent e) {adaptee.menuItem6_actionPerformed (e);}} class dirFilter implements FilenameFilter {

// private string extension;

/ * public Dirfilter (String Extension) {this.extension = extension;} * /

Public Boolean Accept (File File, String Str) {if (file.isfile ()) {Return False;}}}

Class frame1_menuitem7_actionadapter import.Ava.awt.event.ActionListener {frame1 adaptee

Frame1_MenuiteM7_ActionAdapter (frame1 adaptee) {this.adaptee = adaptee;} public void actionperformed (ActionEvent E) {adaptee.menuitem7_actionperformed (e);}}

Class frame1_menuitem8_actionadapter import.Ava.awt.Event.ActionListener {Frame1 Adaptee

Frame1_menuItem8_actionAdapter (Frame1 adaptee) {this.adaptee = adaptee;} public void actionPerformed (ActionEvent e) {adaptee.menuItem8_actionPerformed (e);}} class Frame1_menuItem9_actionAdapter implements java.awt.event.ActionListener {Frame1 adaptee;

Frame1_MenuiteM9_ActionAdapter (frame1 adaptee) {this.adaptee = adaptee;} public void actionPerformed (ActionEvent E) {adaptee.menuitem9_actionperformed (e);}}

Class frame1_menuitem10_actionAdapter Implements java.awt.event.Adlistener {frame1 adaptee;

Frame1_menuItem10_actionAdapter (Frame1 adaptee) {this.adaptee = adaptee;} public void actionPerformed (ActionEvent e) {adaptee.menuItem10_actionPerformed (e);}} class about extends JFrame {public about () {super ( "about pic"); JLabel lb = New Jlabel (" pic1.0 Write by tomcatlee 2004.7" "

Tomcatlee2003@yahoo.com.cn

Class frame1_menuitem11_actionadapter import.Ava.awt.Event.ActionListener {frame1 adaptee

Frame1_menuitem11_ActionAdapter (frame1 adaptee) {this.adaptee = adaptee;} public void actionperformed (ActionEvent E) {adaptee.menuitem11_actionperformed (e);}}

转载请注明原文地址:https://www.9cbs.com/read-17039.html

New Post(0)