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