开发者

PNG with transparency from Photoshop to Flash: how to make .swf display exactly what .psd does?

I have two layers in Photoshop: 1 -- a texture, 2 -- a semi-transparent image that overl开发者_如何学Goaps texture. The combination of the two looks nice in Photoshop. I export them separately from Photoshop saving them as 24 bit PNG with transparency and colors converted to sRGB. (Working color space of PS is sRGB.)

The result of importing them into flash makes me cry (see images below, note what areas around crosses look like). :(

I tried both loading PNGs dynamically and directly importing them into fla (compression type: lossles, allow smoothing: false). Looks like semi-transparent areas are saved inacurately on export. What's more puzzling to me is why the results differ between dynamic loading and direct importing.

What am I missing? In-depth explanation of these symptoms would be highly appreciated.


EDIT1 Here is that psd I'm stuck upon. Inside the zip you'll find transparency.psd, which has only two layers. I still have no luck in placing them into fla: transparent areas get dirty.

http://noregret.org/test/transparency.zip (400 kb)


EDIT2 A fellow flash developer pointed me to "premultiplied alpha problem".

http://en.wikipedia.org/wiki/Alpha_compositing#Description

I think this must be the problem I'm trying to overcome.

As far as I know by now, Photoshop internally uses straight alpha (premultiplying with white on PNG export) and Flash uses premultiplied alpha. But I still don't get it: what yields the difference in rendering of transparent images? And I still don't know exactly what operations I need to perform to get things look the same in PS and Flash (or at least how do I instruct our artists on preparing the images).

Anyone? I'm continuing to dig Google for the answer.


EDIT3 Unfortunatelly, I can't flattern image. This example here is just a small part of a bigger picture. I have a rather complicated interface with a lot of semi-transparent elements on top of a texture. The picture looks cool (like it's made of crumpled cardboard or something). So, I need a texture and semi-transparent layout separately. Adding blendmodes to top layer in flash does solve "the ghosting areas" problem, but it also significantly changes the picture, which is not acceptable.


Semi-transparent layer:

PNG with transparency from Photoshop to Flash: how to make .swf display exactly what .psd does?

Texture layer:

PNG with transparency from Photoshop to Flash: how to make .swf display exactly what .psd does?

Results (screenshots of PS and Flash Player on Windows):

  • Photoshop(original): Ok
  • Flash (import to fla): heavy ghost area
  • Flash (png loading): light ghost area

PNG with transparency from Photoshop to Flash: how to make .swf display exactly what .psd does?


It looks like you are getting JPEG image format with compression inside your FLA, not PNG. And to avoid that, you need to specify that your image compression should be lossless. You can do that in library or in MovieClip props.


Are you using Bitmap objects to render the images above? I had encountered a similar problem with overlapping 2 objects with alpha before where the top-most object's alpha created visual artifacts similar to what you are showing. Using Bitmap's native alpha blending I was never able to correctly fix the problem. My solution was combining them manually using the copyPixels function. Something like this :

public function mergeImgs(baseImg : Bitmap, topImg : Bitmap) : void
{
    baseImg.bitmapData.copyPixels(topImg.bitmapData, topImg.bitmapData.rect, new Point(), null, null, true);
}


Why do these HAVE to be imported as separate layers. You could just flatten the image in photoshop and import it.

Yes, you lose some of the inherent flexibility, but sometimes we have to make these compromises.

That said here are your options:

  1. Switch the blending mode of the top(semi-transparent) layer to lighten. This will get rid of that ugly ring, however it will also dampen the overall effect so you will have to compensate for that in photoshop. This is the easier way.

  2. Implementing the alpha composting yourself, the way you need it, in PixelBender.

  3. Flatten, cut out the exact effect area, then overlay those over your original background texture in flash. Hackish, yes, but it should work.

Cheers!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜