Java concatenates multiple images and can be connected together

Source: Internet
Author: User
/*** Java concatenate multiple images ** @ Param pics * @ Param type * @ Param dst_pic * @ return */public static Boolean Merge (string [] pics, string type, string dst_pic) {int Len = pics. length; If (LEN <1) {system. out. println ("pics Len <1"); Return false;} file [] src = new file [Len]; bufferedimage [] images = new bufferedimage [Len]; int [] [] imagearrays = new int [Len] []; for (INT I = 0; I <Len; I ++) {try {SRC [I] = new file (P ICS [I]); images [I] = ImageIO. read (SRC [I]);} catch (exception e) {e. printstacktrace (); Return false;} int width = images [I]. getwidth (); int Height = images [I]. getheight (); imagearrays [I] = new int [width * Height]; // read rgbimagearrays [I] = images [I] From the image. getrgb (0, 0, width, height, imagearrays [I], 0, width);} int dst_height = 0; int dst_width = images [0]. getwidth (); For (INT I = 0; I <images. length; I ++) {DST _ Width = dst_width> images [I]. getwidth ()? Dst_width: Images [I]. getwidth (); dst_height + = images [I]. getheight ();} system. out. println (dst_width); system. out. println (dst_height); If (dst_height <1) {system. out. println ("dst_height <1"); Return false;} // generate a new image. Try {// dst_width = images [0]. getwidth (); bufferedimage imagenew = new bufferedimage (dst_width, dst_height, bufferedimage. type_int_rgb); int height_ I = 0; For (INT I = 0; I <images. length; I ++) {imagenew. setrgb (0, height_ I, dst_width, images [I]. getheight (), imagearrays [I], 0, dst_width); height_ I + = images [I]. getheight () ;}file OUTFILE = new file (dst_pic); ImageIO. write (imagenew, type, OUTFILE); // write image} catch (exception e) {e. printstacktrace (); Return false;} return true ;}

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.