Java merge Image: Merge multiple images vertically, java vertical

Source: Internet
Author: User

Java merge Image: Merge multiple images vertically, java vertical
Code:

/*** Append an image with the same width vertically. # Note: the width must be the same. ** @ param piclist * file path List * @ param outPath * output path */public static void yPic (List <String> piclist, String outPath) {// if (piclist = null | piclist. size () <= 0) {System. out. println ("the Image array is empty! "); Return;} try {int height = 0, // total height width = 0, // total width _ height = 0, // temporary height, or save the offset height _ height = 0, // temporary height, mainly save each height picNum = piclist. size (); // number of images File fileImg = null; // Save the read image int [] heightArray = new int [picNum]; // Save the height of each file BufferedImage buffer = null; // Save the image stream List <int []> imgRGB = new ArrayList <int []> (); // Save the RGBint [] _ imgRGB of all images; // Save the RGB data in an image for (int I = 0; I <picNum; I ++) {fileImg = New File (piclist. get (I); buffer = ImageIO. read (fileImg); heightArray [I] = _ height = buffer. getHeight (); // Image Height if (I = 0) {width = buffer. getWidth (); // Image width} height + = _ height; // obtain the total height _ imgRGB = new int [width * _ height]; // read RGB_imgRGB = buffer from the image. getRGB (0, 0, width, _ height, _ imgRGB, 0, width); imgRGB. add (_ imgRGB);} _ height = 0; // set the offset height to 0 // generate a new image BufferedImage imageResult = new BufferedImage (width, Height, BufferedImage. TYPE_INT_RGB); for (int I = 0; I <picNum; I ++) {__ height = heightArray [I]; if (I! = 0) _ height + = _ height; // calculate the offset height imageResult. setRGB (0, _ height, width, _ height, imgRGB. get (I), 0, width); // write stream} File outFile = new File (outPath); ImageIO. write (imageResult, "jpg", outFile); // write image} catch (Exception e) {e. printStackTrace ();}}


Call:
public static void main(String[] args) {List<String> list = new ArrayList<String>();list.add("f:/bak/image/1.jpg");list.add("f:/bak/image/2.jpg");list.add("f:/bak/image/1.jpg");yPic(list, "f:/bak/image/3.jpg");}



Write something more slowly later


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.