FFImageLoading icon indicating copy to clipboard operation
FFImageLoading copied to clipboard

On Android TransparencyEnabled = false on a PNG shows transparency

Open lecnierfreeman opened this issue 10 years ago • 2 comments

If you open the FFImageLoading Sample app and click on Basic example option but before go to the source code of that page and replace the source of the CachedImage for a PNG with alpha channel( I used this one) with the option TransparencyEnabled = false on Android should show the image without transparency. Tested on VS Simulator and Samsung Note 4

lecnierfreeman avatar Aug 10 '16 14:08 lecnierfreeman

I was checking the source code and I think the problem is because you are only setting the desired pixel format in the preferred decoder options: options.InPreferredConfig = Bitmap.Config.Rgb565; (ImageLoaderTask.cs Ln:371) but this doesn't force the decoder to use that format. I located this line:
bitmap = BitmapFactory.DecodeStream(stream, null, options); and tried to add this after:

                    if (options.InPreferredConfig == Bitmap.Config.Rgb565 && bitmap.HasAlpha)
                    {
                        var newBitmap = Bitmap.CreateBitmap(bitmap.Width, bitmap.Height, Bitmap.Config.Rgb565);
                        var c = new Canvas(newBitmap);
                        c.DrawColor(Color.White);
                        var p = new Paint();
                        c.DrawBitmap(bitmap, 0, 0, p);
                        bitmap.Recycle();
                        bitmap = newBitmap;                     
                    }

and now I get the desired image without alpha channel and looks similar to IOS behavior.

lecnierfreeman avatar Aug 10 '16 16:08 lecnierfreeman

Read this: http://stackoverflow.com/questions/14633003/rgb565-for-sprites It's in preferred decoder options because of performance reasons.

daniel-luberda avatar Sep 06 '16 04:09 daniel-luberda