Java Merge Picture: Merge multiple pictures vertically together

Source: Internet
Author: User

Code:

/** * The same width of the picture, vertically appended to the # #注意: The width must be the same * * @param piclist * file path list * @param outpath * Output path */public STA tic void Ypic (list<string> piclist, String outpath) {//Portrait processing picture if (piclist = null | | piclist.size () <= 0) {System . OUT.PRINTLN ("Picture array is empty!"); return;} try {int height = 0,//gross height width = 0,//total width _height = 0,//temporary height, or save offset height __height = 0,//temporary height, main save per height Picnum = piclist . Size ();//number of pictures file fileimg = null; Save the read-out picture int[] Heightarray = new Int[picnum]; Save the height of each file bufferedimage buffer = null; Save Picture Stream list<int[]> Imgrgb = new arraylist<int[]> (); Save all pictures of the rgbint[] _imgrgb; Save the RGB data in a picture for (int i = 0; i < Picnum; i++) {fileimg = new File (Piclist.get (i)); buffer = Imageio.read (fileimg); Hei Ghtarray[i] = _height = Buffer.getheight ();//Picture height if (i = = 0) {width = Buffer.getwidth ();//Picture width}height + = _height; Get total Height _imgrgb = new Int[width * _height];//read from picture Rgb_imgrgb = Buffer.getrgb (0, 0, width, _height, _imgrgb, 0, width); im Grgb.add (_IMGRGB);} _height = 0; Set the offset height to 0//generate a new picture 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 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 Picture} catch (Exception e) {e.printst Acktrace ();}}


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 else slowly later.


Java Merge Picture: Merge multiple pictures vertically together

Related Article

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.