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