Java Mosaic more than one picture, you can connect together __java

Source: Internet
Author: User
/** * java mosaic multiple pictures * * @param pics * @param type * @param dst_pic * @return/public static Boolean merge (S)
		Tring[] 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 (pics[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];//reads RGB imagearrays[i from picture] = Images[i].getrgb (0, 0, width, height, image
		Arrays[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 new picture 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 (), imag
				Earrays[i], 0, dst_width);
			Height_i + + images[i].getheight ();
			} file outfile = new file (dst_pic);
			Imageio.write (imagenew, type, outfile);//Write Picture} 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.