0

I want to get bitmap from imageview with vectordrawable resource that rotated on X or Y axis but the quality of bitmap is not good. The quality without rotation or "setRotation" is good but when I use "setRotationX" or "setRotationY" or Camera to rotate, the bitmap quality comes down. This problem is just when I set "setImageResource" to a vectordrawable, jpeg or png images have not this problem. I think this is a bug on vectordrawable...

This is my code to get a bitmap:

itemBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(itemBitmap);
cv.save();
imageView.draw(canvas);
cv.restore();
XDelta
  • 43
  • 2
  • 7

2 Answers2

0

If you're trying to get a bitmap from an imageView, the quality of the bitmap is more likely to be degraded. If the image is rotated it will have even less quality as the bitmap needs to be zoomed out.

You can try following things:

  • convert the vector resource directly into bitmap and rotate using matrix or some libraries. or,
  • turn off hardware acceleration. or,
  • Use imageView.setDrawingCacheEnabled(false); followed by Bitmap bitmap = imageView.getDrawingCache();
Nabin Bhandari
  • 15,949
  • 6
  • 45
  • 59
  • convert to the bitmap does not help me, because I need resize the imageview and vector does not lose its quality, if I wanted to use bitmap I did not use the vector! I tested hardware acceleration before and did not affect, also bitmap quality of imageView.draw(canvas) is better than getDrawingCache() for this reason I use imageView.draw(canvas) – XDelta Oct 10 '17 at 12:01
0

Pl refer to kc Ochibili's answer for question at following address:

How to Get Pixel Colour in Android?

I am using same on my VectorDrawable like (what I have shown below). I am giving code details like a narration because I am posting this from my mobile and there is problem with indentation which is not accepted by the system at stackoverflow.

First attach a listener to the ImageView like myImageView.setOnTouchListener(new View.OnTouchListener(){ Then override the following method: Public boolean onTouch(View view, MotionEvent motionEvent){ Then from the view parameter received take IageView ImageView img = (ImageView) view; Then on the image view do the following: Img.setDrawingCacheEnablef(true); Then take bitmap from that Bitmap imgbmp = Bitmap.createBitmap(img.getDrawingCache()); Immediately setDrawingCacheEnabled(false) on img.

You have the bitmap.

  • bitmap quality of imageView.draw(canvas) is better than getDrawingCache() for this reason I use imageView.draw(canvas) – XDelta Oct 10 '17 at 12:34