The picture contrast when want to put two different pictures together, convenient for manual view, search on the Internet, there are vertical merger.
The vertical merger of the self-adjustment, the source code is as follows:
ImportJava.io.File;ImportJava.awt.image.BufferedImage;ImportJavax.imageio.ImageIO; Public classTestpic { Public Static voidMain (string[] args) {xpic (); }
Public Static voidXpic () {//Landscape processing Picture Try { /*1 reading the first picture*/File Fileone=NewFile ("E:\\1.png"); BufferedImage ImageFIRST=Imageio.read (Fileone); intwidth = Imagefirst.getwidth ();//Picture Width intHeight = imagefirst.getheight ();//Picture Height int[] Imagearrayfirst =New int[Width * height];//reading RGB from a pictureImagearrayfirst = Imagefirst.getrgb (0, 0, width, height, imagearrayfirst, 0, width); /*1 Do the same with the second picture*/File Filetwo=NewFile ("E:\\2.png"); BufferedImage Imagesecond=Imageio.read (Filetwo); int[] Imagearraysecond =New int[Width *height]; Imagearraysecond= Imagesecond.getrgb (0, 0, width, height, imagearraysecond, 0, width); //Create a new pictureBufferedImage Imageresult =NewBufferedImage (Width * 2, Height,bufferedimage.type_int_rgb); Imageresult.setrgb (0, 0, width, height, imagearrayfirst, 0, width);//sets the RGB of the left halfImageresult.setrgb (width, 0, width, height, imagearraysecond, 0, width);//set RGB in right halfFile OutFile =NewFile ("D:\\out.jpg"); Imageio.write (Imageresult,"JPG", outFile);//Write a picture}Catch(Exception e) {e.printstacktrace (); } } Public Static voidYpic () {//Portrait processing picture Try { /*1 reading the first picture*/File Fileone=NewFile ("D:\\1.gif"); BufferedImage ImageFIRST=Imageio.read (Fileone); intwidth = Imagefirst.getwidth ();//Picture Width intHeight = imagefirst.getheight ();//Picture Height int[] Imagearrayfirst =New int[Width * height];//reading RGB from a pictureImagearrayfirst = Imagefirst.getrgb (0, 0, width, height, imagearrayfirst, 0, width); /*1 Do the same with the second picture*/File Filetwo=NewFile ("D:\\1.gif"); BufferedImage Imagesecond=Imageio.read (Filetwo); int[] Imagearraysecond =New int[Width *height]; Imagearraysecond= Imagesecond.getrgb (0, 0, width, height, imagearraysecond, 0, width); //Create a new pictureBufferedImage Imageresult =NewBufferedImage (width, Height * 2, Bufferedimage.type_int_rgb); Imageresult.setrgb (0, 0, width, height, imagearrayfirst, 0, width);//sets the RGB of the left halfImageresult.setrgb (0, height, width, height, imagearraysecond, 0, width);//set RGB in right halfFile OutFile =NewFile ("D:\\out.jpg"); Imageio.write (Imageresult,"JPG", outFile);//Write a picture}Catch(Exception e) {e.printstacktrace (); } }}
can be run directly.
This article transferred from: http://cxr1217.iteye.com/blog/1638681
Java Landscape, portrait merge picture