Android 如何剪切位图的中间区域?
我该如何切出中间区域位图? 这是我的示例代码:Android 如何剪切位图的中间区域?,android,Android,我该如何切出中间区域位图? 这是我的示例代码: public void onPictureTaken(byte[] paramArrayOfByte, Camera paramCamera) { 您可能需要使用的另一个重载-它具有x、y、宽度和高度参数,您可以使用这些参数将位图的中间部分裁剪为新位图 大概是这样的: Bitmap crapped=Bitmap.createBitmap(sourceBitmap,50,50,sourceBitmap.getWidth()-100,sourc
public void onPictureTaken(byte[] paramArrayOfByte, Camera paramCamera)
{
您可能需要使用的另一个重载-它具有x、y、宽度和高度参数,您可以使用这些参数将位图的中间部分裁剪为新位图 大概是这样的:
Bitmap crapped=Bitmap.createBitmap(sourceBitmap,50,50,sourceBitmap.getWidth()-100,sourceBitmap.getHeight()-100);
从边缘剪切50像素的所有内容。乍一看,这段代码似乎确实用getPixels()剪切了位图的中间部分你是不是犯了一个错误,还是试图做别的事情?我在XY XY中给出了一个错误,更确切地说,我不知道如何指定一个坐标位置,它会在MyI图中间剪出一个矩形。当你只说“一个错误”而不是提供错误信息时,很难帮助你。非常感谢你帮助了我!
FileOutputStream fileOutputStream = null;
try {
File saveDir = new File("/sdcard/CameraExample/");
if (!saveDir.exists())
{
saveDir.mkdirs();
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 5;
Bitmap myImage = BitmapFactory.decodeByteArray(paramArrayOfByte, 0,paramArrayOfByte.length, options);
Bitmap bmpResult = Bitmap.createBitmap(myImage.getWidth(), myImage.getHeight(),Config.RGB_565);
int length = myImage.getHeight()*myImage.getWidth();
int[] pixels = new int[length];
myImage.getPixels(pixels, 0, myImage.getWidth(), 0,0, myImage.getWidth(), myImage.getHeight());
Bitmap TygolykovLOL = Bitmap.createBitmap(pixels, 0, myImage.getWidth(), myImage.getWidth(),myImage.getHeight(), Config.RGB_565);
Paint paint = new Paint();
Canvas myCanvas = new Canvas(bmpResult);
myCanvas.drawBitmap(TygolykovLOL, 0, 0, paint);
fileOutputStream = new FileOutputStream("/sdcard/CameraExample/" + "1ggggqqqqGj2.bmp");
BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream );
bmpResult.compress(CompressFormat.PNG, 100, bos);
bos.flush();
bos.close();