Java Landscape, portrait merge picture

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.