Resize png image in Delphi - incorrect alpha channel

三世轮回 提交于 2019-12-12 13:50:11

问题


I am resizing png images which might have alpha channel.

Everything works good, with one exception: I get some gray pixels around the transparent areas.

The original image doesn't have any drop shadows.

Is there a way to fix this / work it around?

I am using SmoothResize by Gustavo Daud (See the first answer to this question), to resize the png image.

I cannot provide the code that I am using as I did not write it and do not have the author's permission to publish it.


回答1:


I suspect that is caused by 2 things: funny RGBA values in PNG and naive resizing code.

You need to check your PNG contents. You are looking for RGB values in transparent areas. Despite transparent areas having Alpha at 0, they still have an RGB info. In your case I would expect that transparent areas are filled with black RGB value. That is what might cause the grey outline after resize if the resize is done naively. Example: What happens if code resizes 2 adjustent pixels (0,0,0,0) and (255,255,255,255) into one? Both pixels contribute by 50% The result is 128,128,128,128) which is semi-transparent grey. Same thing happens when you upscale by e.g x1.5, the added pixel inbetween original two will be grey. Usually that does not happen because image-editing software is smart enough to fill those invisible pixels with color from nearest visible pixel.

You can try to "fix" the PNG by filling transparent areas with white (or another color that is on border of your images).

Another approach is to use an advanced resizing code (write or find library), that will ignore transparent pixels RGB values (e.g. by taking RGB from closest non-transparent pixel).



来源:https://stackoverflow.com/questions/18596172/resize-png-image-in-delphi-incorrect-alpha-channel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!