Split Picture
Java code private static void splitimage () throws IOException { String originalImg = "c:\\img \\split\\a380_1280x1024.jpg "; // read the big picture file file = new file (originalimg); Fileinputstream fis = new fileinputstream (file); Bufferedimage image = imageio.read (FIS); // Split into 4*4 (16) A small map int rows = 4; int cols = 4; int chunks = rows * cols; // Calculate the width and height of each small map int&nBsp;chunkwidth = image.getwidth () / cols; int Chunkheight = image.getheight () / rows; int count = 0; BufferedImage imgs[] = new bufferedimage[chunks]; for (int x = 0; x < rows; x++) { for (int y = 0; y < cols; y++) { //the size and type of the small chart imgs[count] = new bufferedimage (chunkwidth, chunkheight, Image.gettype ()); //Write image content graphics2d gr = imgs[count++].creategraphics (); gr.drawimage (image, 0, 0, chunkwidth, chunkheight, chunkWidth* y, chunkHeight * x, chunkWidth * y + chunkWidth, chunkheight * x + chunkheight, nulL); gr.dispose (); } } // output Small figure for (int i = 0; i < imgs.length; i++) { imageio.write (imgs[i], "JPG", new file ("C:\\img\\split\\img" + i + ". jpg"); } &NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN ("complete segmentation.") "); }
Stitching Pictures
Java code private static void mergeimage () throws IOException { int rows = 2; int cols = 2; int chunks = rows * cols ; int chunkWidth, chunkHeight; int type; //Read Small map File[] imgFiles = new File[chunks]; for (int i = 0; i < chunks; i++) { imgfiles[i] = new file ("C:\\img\\merge\\img" + i + ". jpg"); } // Create bufferedimage BufferedImage[] buffImages = new BufferedImage[chunks]; for (int i = 0; i < chunks; i++ ) { buffimages[i] = imageio.read ( Imgfiles[i]); } type = Buffimages[0].gettype (); chunkwidth = buffimages[0].getwidth (); chunkheight = buffimages[0].getheight (); //sets the size and type of the picture after stitching bufferedimage finalimg = new bufferedimage (Chunkwidth * cols, chunkheight * rows, type);
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