How to implement merging pictures with Java programming

Source: Internet
Author: User

For many of the methods of implementing picture merging with Java have many, below I will share a Java implementation of the image merge code to everyone, specifically as follows:

1. Package com.test;

2. Import Java.io.File;

3. Import Java.awt.image.BufferedImage;

4. Import Javax.imageio.ImageIO;

5. public class Imagecombinetest {

6. public static void Main (String args[]) {

7. try {

8.//Read the first picture

9. File Fileone = new file ("/users/coolcloud/pictures/art/lena-2.jpg");

BufferedImage Imageone = Imageio.read (Fileone);

one. int width = imageone.getwidth ();

12.//Picture width

int height = imageone.getheight ();

14.//Picture height

15.//read RGB from Picture

int[] Imagearrayone = new int[width * height];

Imagearrayone = Imageone.getrgb (0, 0, width, height, imagearrayone,

0, width);

19.//Do the same with the second picture

File Filetwo = new file ("/users/coolcloud/pictures/art/lena-2.jpg");

BufferedImage imagetwo = Imageio.read (filetwo);

int[] Imagearraytwo = new int[width * height];

Imagearraytwo = Imagetwo.getrgb (0, 0, width, height, imagearraytwo,

0, width);

25.//Create new picture

//BufferedImage imagenew = new BufferedImage (Width * 2, height,

//BUFFEREDIMAGE.TYPE_INT_RGB);

BufferedImage imagenew = new BufferedImage (width*2, Height*2,

BUFFEREDIMAGE.TYPE_INT_RGB);

Imagenew.setrgb (0, 0, width, height, imagearrayone, 0, width);

31.//Set RGB in left half

//Imagenew.setrgb (width, 0, width, height, imagearraytwo, 0, width);//Set RGB in right half

//Imagenew.setrgb (0, height, width, imageone.getheight () +imagetwo.getheight (), Imagearraytwo, 0, width);// Set RGB in right half

Imagenew.setrgb (0, height, width, height, imagearraytwo, 0, width);

35.//Set RGB in right half

File OutFile = new file ("/users/coolcloud/pictures/generatepic.jpg");

Panax Notoginseng imageio.write (imagenew, "PNG", outFile);

38.//Write a picture

39.}

. catch (Exception e) {

E.printstacktrace ();

42.}

43.}

44.}

If you do not know the friend can add me Q, or add group number to study together, we learn to share video programming, hope to help like Java friends. If you need any help, you can contact me.

How to implement merging pictures with Java programming

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.