我想使用DragReactangle裁剪位图我想相对于绘制在其上的Rectangle的尺寸来裁剪位图。这是我的CropBitmap方法
public static Bitmap getCroppedImage(Bitmap mBitmap) {
//mRectLeft = left of rectangle
//mRectRight = right of rectangle
//mRectTop = top of rectangle
//mRectBottom = Bottom of rectangle
if ((sKeyRectX <= 0 && sKeyRectY <= 0 && sKeyRectWidth <= 0 && sKeyRectHeight <= 0)) {
//If items are not initialized then we return the original bitmap
return mBitmap;
}
double ratioHeight = ((double) mBitmap.getHeight() /(double) sKeyRectHeight);
double ratioWidth = ((double) mBitmap.getWidth() /(double) sKeyRectWidth);
/**
* Do sanity checks i.e. y+height should be less than bitmap and x+width less than width of bitmap
*/
double width = sKeyRectWidth * ratioWidth;
double height = sKeyRectHeight * ratioHeight;
double start_x_pixel = sKeyRectX * ratioWidth;
double start_y_pixel = sKeyRectY * ratioHeight;
start_x_pixel = start_x_pixel <= mBitmap.getWidth() ? start_x_pixel : mBitmap.getWidth();
start_y_pixel = start_y_pixel <= mBitmap.getHeight() ? start_y_pixel : mBitmap.getHeight();
if (width + start_x_pixel > mBitmap.getWidth()) {
width = mBitmap.getWidth() - start_x_pixel;
return mBitmap;//return the original bitamp
}
if (height + start_y_pixel > mBitmap.getHeight()) {
height = mBitmap.getHeight() - start_y_pixel;
return mBitmap;//return the original bitamp
}
Bitmap cropedBitmap = Bitmap
.createBitmap(mBitmap, (int) start_x_pixel, (int) start_y_pixel,
(int) width,
(int) height
);
return cropedBitmap;
}
我希望我在其他活动中使用此静态裁切函数来获取裁切后的图像,并且将Rectangle的顶部,左侧,右侧,底部存储在共享的首选项中,以便我可以调用图像并将它们在相同的位置处剪切第一次。
我该如何实现