Android black outline around bitmap

I’m drawing movieclips from swf to bitmap and it seems that on some bitmaps a black outline in being drawn when I set smoothing to true. Evertyhing is fine when I’m not using smoothing or set antialiasing in application.xml to 0. Windows, flash and neko targets work fine. I’m using OpenFL 2.0.

[code]xml:

var mc:MovieClip = swfLibrary.getMovieClip(id);
mc.gotoAndStop(frame);
var bounds:Rectangle = mc.getBounds(Lib.current.stage);
var mcBitmapData:BitmapData = new BitmapData(Math.ceil(mc.width * scale), Math.ceil(mc.height * scale), true, 0x00000000);
var matrix1:Matrix = new Matrix();
matrix1.translate(-bounds.x, -bounds.y);
matrix1.scale(scale, scale);
mcBitmapData.draw(mc, matrix1, null, null, null, smoothing);
return new Bitmap(mcBitmapData, PixelSnapping.AUTO, smoothing); [/code]

When OpenGL applies hardware-based smoothing, it applies it equally to all color channels. The problem is that ideally, you want the R, G and B channels to be smoothed, but only where the alpha is greater than zero. There’s no hardware option for that.

Depending on your image editor, it may optimize transparent pixels to be black, in order to save on file space. This means that when it is smoothed, it may “pull in” some of those black pixels when it smooths. The solution is to use an editor that preserves alpha pixels, and to set them to a color similar to the rest of the image, or another solution is to use premultiplied alpha in the renderer.

OpenFL “next” is designed to use premultiplied alpha, so this problem has gone away. Flash Player also uses premultiplied alpha. I have tried on multiple occasions to apply premultiplied alpha to the older native codebase, but kept running into issues. There is a define that could be used when recompiling it to try enabling premultiplied alpha, but there are a couple instances where it behaves incorrectly

2 Likes

Thank you very much for detailed answer :smile:
I guess OpenFL Next is the way to go in that case.

This topic is kind of old but I’ve found a solution to this some time ago, might be useful to someone.
Drawing movieclips to semi-transparent bitmapdatas fixes this in most cases. So instead of “new BitmapData(bdmWidth, bdmHeight, true, 0x00000000);” I’m using “new BitmapData(bdmWidth, bdmHeight, true, 0x014894C2);”

vs

It might look bad on white backgrounds but in most cases it works for me :slight_smile:

1 Like

Oh, that’s a good idea :slight_smile:

Perhaps the same trick would work on a white background, using 0x01FFFFFF?

Yes, but if sprite is moving around the screen and background color behind it changes to something bright, bitmap’s fill color might become visible :slight_smile: Or if the fill color is white then it might become visible on dark background. But I’m not really sure if such alpha is visible to human eye.