daimons / androidsvg

Automatically exported from code.google.com/p/androidsvg
1 stars 0 forks source link

Rendering on grayscale bitmap fails #7

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Bitmap bm = Bitmap.createBitmap((int) w, (int) h, Bitmap.config.ALPHA_8);
Canvas bmcanvas = new Canvas(bm);

// Render our document scaled to fit inside our canvas dimensions
svg.renderToCanvas(bmcanvas, null, 96f, AspectRatioAlignment.xMidYMid, 
AspectRatioScale.MEET);

What is the expected output? What do you see instead?
I expected bm to be a grayscale bitmap, instead it is all black.

What version of the product are you using? On what operating system?
Latest

Please provide any additional information below.

Original issue reported on code.google.com by argonned...@gmail.com on 17 Jun 2013 at 7:32

GoogleCodeExporter commented 9 years ago

Original comment by paul.leb...@gmail.com on 17 Jun 2013 at 10:51

GoogleCodeExporter commented 9 years ago
ALPHA_8 doesn't create an 8-bit greyscale bitmap. It creates a bitmap that 
represents an alpha channel. From the Bitmap javadoc:

"Each pixel is stored as a single translucency (alpha) channel."

If you need a greyscale bitmap, you would need to render to a 565 or 8888. Then 
convert it yourself, or paint the bitmap using a ColorMatrixColorFilter.

For an exmple of the latter, see: 
http://stackoverflow.com/questions/3373860/convert-a-bitmap-to-grayscale-in-andr
oid 

Marking Invalid, as this is not a bug with the library.

If there is demand, I may add ColorMtrix support to the library in a future 
version.

Original comment by paul.leb...@gmail.com on 17 Jun 2013 at 11:22