Android to cut a picture into more than one image of the implementation method _android

Source: Internet
Author: User

Here are two packaged classes that enable you to cut pictures. For reference and study only.

One is the Imagepiece class, which holds a bitmap object and an int variable that identifies the sequential index of the picture.

Copy Code code as follows:

Package arui319.blog.csdn.net;

Import Android.graphics.Bitmap;

public class Imagepiece {

public int index = 0;

Public Bitmap Bitmap = null;
}

One is the Imagesplitter class, which has a static method for split, and the incoming parameter is the bitmap object to be cut, and the number of horizontal and vertical cutting pieces. For example, the incoming is 3, 3, then all cut into 3, will eventually cut the entire picture into 3x3=9 slices.
Copy Code code as follows:

Package arui319.blog.csdn.net;

Import java.util.ArrayList;
Import java.util.List;

Import Android.graphics.Bitmap;

public class Imagesplitter {

public static list<imagepiece> Split (Bitmap Bitmap, int xpiece, int ypiece) {

list<imagepiece> pieces = new Arraylist<imagepiece> (xpiece * ypiece);
int width = bitmap.getwidth ();
int height = bitmap.getheight ();
int piecewidth = WIDTH/3;
int pieceheight = HEIGHT/3;
for (int i = 0; i < ypiece; i++) {
for (int j = 0; J < Xpiece; J + +) {
Imagepiece piece = new Imagepiece ();
Piece.index = j + i * xpiece;
int xvalue = J * Piecewidth;
int yvalue = i * pieceheight;
Piece.bitmap = Bitmap.createbitmap (Bitmap, Xvalue, Yvalue,
Piecewidth, Pieceheight);
Pieces.add (piece);
}
}

return pieces;
}

}

Here the cutting, mainly using the bitmap object of the CreateBitmap method, no longer do a specific description.

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.