I am trying to get these x1, x2, y1, y2 co-ordinates of the image cropper according this image.
Any help regarding this?
following link is the library i am using for image cropping. Android-Image-Cropper
Although Using thirdparty libraries are advised for beginners, sometimes is not the best choice, especially if there is an implementation of whatever you want to do in the android SDK, take a look at this tutorial for example:
https://code.tutsplus.com/tutorials/capture-and-crop-an-image-with-the-device-camera--mobile-11458
Now for your problem, you can approach this in many ways:
Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.yourImage);
croppedImage = Bitmap.createBitmap(mBitmap, 0 , 0 , desiredwidth, desiredheight);
Using the answer above does not work if you want to crop out of bounds areas
Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.yourImage);
Rect mRect= new Rect(x1, y1, x2, y2);
assert(mRect.left < mRect.right && mRect.top < mRect.bottom);
Bitmap croppedImage = Bitmap.createBitmap(rect.right-rect.left, rect.bottom-rect.top, Bitmap.Config.ARGB_8888);
new Canvas(croppedImage).drawBitmap(mBitmap, -rect.left, -rect.top, null);
PS: Please check the android sdk before you use any libraries there are alot of good examples and it will decrease the use of unnecessary libraries, and it will make you understand the underlying code better.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.