Android. How can I make an ImageView draw itself as a PNG?

145 views Asked by At

An ImageView has been loaded with a 1514 × 564 PNG image of 67KB.

A LinearLayout, containing several views including such ImageView, needs to be drawn into a canvas. When calling the method ImageView.draw(Canvas), the canvas size in bytes increases from 67KB to 13MB! (because "draw" draws the bitmap, not the compressed PNG)

Is there an easy way to make imageView draw itself as a PNG?

So far, I've thought of extending ImageView and overriding the draw method with something that compresses the bitmap before drawing.

1

There are 1 answers

2
CommonsWare On

Is there an easy way to make imageView draw itself as a PNG?

No, because there is no such concept. Moreover, you already have the PNG, so it is unclear why you are calling draw()` in the first place. If you want a PNG, use your PNG.

So far, I've thought of extending ImageView and overriding the draw method with something that compresses the bitmap before drawing.

That would be pointless, as you would then need to re-decompress the image before drawing it. Canvas draws a Bitmap, not a PNG, and a Bitmap is the decompressed image.