Issue
I have my view converted to bitmap image, and I want to cut part from bottom and top. My problem is that I can do one of them, but when I want to do another, it annuls previous work. Here is my code:
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);
And here is the picture, so you can better see what I want to cut (arrows show those parts). Thank you.
Solution
This will cut you Bitmap from top and bottom and takes the center path and the condition if (srcBmp.getWidth() >= srcBmp.getHeight())
tells if width greater than height then it will cut horizontally .
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()
);
}
Answered By - Asad Ali Answer Checked By - Candace Johnson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.