[英]How to crop bitmap image from both top and bottom?
我已將視圖轉換為位圖圖像,並且希望從底部和頂部切割部分。 我的問題是我可以做其中一個,但是當我想做另一個時,它就廢除了以前的工作。 這是我的代碼:
bitImage=getBitmapFromView(_root);
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmapOptions.inTargetDensity = 1;
bitImage.setDensity(Bitmap.DENSITY_NONE);
Bitmap crop=Bitmap.createBitmap(bitImage,0,0,bitImage.getWidth(),((int)(bitImage.getHeight()*0.8)));
crop=Bitmap.createBitmap(anything here will annul previous line);
crop.compress(Bitmap.CompressFormat.PNG,100,out);
這是圖片,因此您可以更好地看到我要剪切的內容(箭頭表示這些部分)。 謝謝。
這將從頂部和底部切割您的位圖,並采用中心路徑和條件, if (srcBmp.getWidth() >= srcBmp.getHeight())
告訴寬度是否大於高度,則它將水平切割。
if (srcBmp.getWidth() >= srcBmp.getHeight()){
dstBmp = Bitmap.createBitmap(
srcBmp,
srcBmp.getWidth()/2 - srcBmp.getHeight()/2,
0,
srcBmp.getHeight(),
srcBmp.getHeight()
);
}else{
dstBmp = Bitmap.createBitmap(
srcBmp,
0,
srcBmp.getHeight()/2 - srcBmp.getWidth()/2,
srcBmp.getWidth(),
srcBmp.getWidth()
);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.