0

I am making a tool to draw on image.I am using custom imageview to draw on it and save the new image to storage in phone. The problem is with the saved image resolution .For low resolution image the final image resolution is as it is. But for high resolution image the final image which I got from ImageView after drawing ,when saved to storage is of low quality and hence image quality becomes bad.

Please suggest me how to save the high resolution image after drawing over it.

Here is the line of code .

 Bitmap signOffBmp = Bitmap.createBitmap(mDrawingView.getDrawingCache());

where

mDrawingView

is custom imageview with draw functionality and

signOffBmp

is final image bitmap with low resolution.

Also I found the link which seems to solve my issue but it doesnot Improve image quality while using getDrawingCache - android Thank you

Community
  • 1
  • 1
Sourabh soni
  • 488
  • 7
  • 11

2 Answers2

0

You should create the bitmap from a resource, and not from the view drawing cache, which is after scaling to screen resolution.

Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.my_drawable);

The Resolution is the number of pixels per display size. for example, if you draw a 500*500 pixels image to fit a 2"*2" square, then the resolution is 250ppi (pixels per inch). If you draw a 1000*1000 pixels image on a 10"*10" square, then the resolution is 100ppi.


When Android draws a bitmap on the screen, it caches only the number of actual screen pixels, and screen resolution typically varies between 170ppi and 340ppi.

Community
  • 1
  • 1
Amir Uval
  • 14,425
  • 4
  • 50
  • 74
  • Thank you for response ...the image loaded from storage is perfect .After drawing on image how can I save it keeping the size as it was initially – Sourabh soni Jan 14 '17 at 09:35
  • sir ..the final image after drawing shape is fetched from ImageView and than saved to storage. , when we take image from imageview ,its quality degrades. – Sourabh soni Jan 14 '17 at 09:48
  • please suggest how can I get final image from imageview without loosing its quality – Sourabh soni Jan 14 '17 at 09:49
  • Don't fetch it from ImageView. This is what I said and tried to explain. – Amir Uval Jan 14 '17 at 11:28
0

This is the source of your problem:

Bitmap signOffBmp = Bitmap.createBitmap(mDrawingView.getDrawingCache());

You are trying to draw the content in the custom ImageView onto the final bitmap. When you do this, you can increase the resolution. You will get the same resolution as that of your Custom ImageView.

If you want to control the resolution while you save the final image, you need to do as below:

  1. You need to keep hold of the original Bitmap of the Image.
  2. Load this original Bitmap on the ImageView after sampling it appropriately
  3. Perform all your custom drawing on top of this ImageView. You need to keep track of all the drawing operation, such that calling a single method will draw everything on the Canvas that you supply.
  4. While you save the image, create a new Bitmap with the resolution that you need.
  5. Create a new Canvas and attach the Bitmap to it.
  6. Draw the Image's Bitmap on to this Canvas.
  7. Now, perform the custom drawing on this Canvas instead of the ImageView. You might need to alter the Matrix of the canvas so that everything is up to scale.
  8. Finally, save this Bitmap to storage.

I am not sure how the current architecture of your app is, so based on that you need to tweak your code to accomplish this.

Henry
  • 17,490
  • 7
  • 63
  • 98