[英]How do I cut out the middle area of the bitmap?
如何剪切位圖的中間區域? 這是我的示例代碼:
public void onPictureTaken(byte[] paramArrayOfByte, Camera paramCamera)
{
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();
您可能希望使用createBitmap
的另一個重載 - 它具有x,y,width和height參數,您可以使用這些參數將位圖的中間部分裁剪為新的位圖。
像這樣的東西:
Bitmap cropped = Bitmap.createBitmap(sourceBitmap, 50, 50, sourceBitmap.getWidth() - 100, sourceBitmap.getHeight() - 100);
從邊緣剪出50像素的所有內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.