I have to crop a bitmap image. For this, I am using
Bitmap bitmap = Bitmap.createBitmap(imgView.getWidth(),imgView.getHeight(), Bitmap.Config.RGB_565);
Bitmap result =Bitmap.createBitmap(bitmap,imgView.getLeft()+10, imgView.getTop()+50, imgView.getWidth()-20, imgView.getHeight()-100);
bitmap.recycle();
Canvas canvas = new Canvas(result);
imgView.draw(canvas);
But it cuts the bottom and right of the bitmap. Top and Left part of the bitmap exists in the output. That means x and y position has no effect.
I am searched for good documentation. But I couldn't.
Thanks in Advance
What is the problem here and how to solve?
❓ How can I resize a BMP image? First, you need to add a BMP image file: drag & drop your BMP image file or click inside the white area to choose a file. Then adjust resize settings, and click the "Resize" button. After the process completes, you can download your result file.
scaleToFitWidth(bitmap, 100); public static Bitmap scaleToFitWidth(Bitmap b, int width) { float factor = width / (float) b. getWidth(); return Bitmap. createScaledBitmap(b, width, (int) (b. getHeight() * factor), true); } // Scale and maintain aspect ratio given a desired height // BitmapScaler.
You can use eraseColor on bitmap to set its color to Transparent. It will useable again without recreating it.
You can do a check when you want to return the BitMap look to see if the ArrayList of Paths is bigger than 0 and return the BitMap if so, or else return null.
Basically your problem arises form the fact that you create a bitmap. You don't put anything in it. You then create a smaller bitmap and then you render an imageView to that smaller bitmap.
This cuts off the bottom 100 pixels and right 20 pixels.
You need to Create the large bitmap. Add the imageview data to that bitmap. Then resize it.
The following code should work:
Bitmap bitmap = Bitmap.createBitmap(imgView.getWidth(),imgView.getHeight(), Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
imgView.draw(canvas);
Bitmap result =Bitmap.createBitmap(bitmap,imgView.getLeft()+10, imgView.getTop()+50, imgView.getWidth()-20, imgView.getHeight()-100);
bitmap.recycle();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With