Note: You must be registered in order to post a reply. To register, click here. Registration is FREE!
T O P I C R E V I E W
soulmonster
Posted - Apr 02 2012 : 03:43:15 When I resize a png image with transparent parts, the resizing of the alphachannel produces grey pixels at the borders of the transparent areas.
ImageFile is a jpg photo and the AlphaFile is a jpg greyscale mask.
Any idea?
Arnd
fab
Posted - Apr 03 2012 : 23:46:22 The code of SetAlphaRangePixelsColor is very simple, so it is possible to extract it from TImageEnView and apply directly to a TIEBitmap object:
procedure SetAlphaRangePixelsColor(Bitmap:TIEBitmap);
var
col, row: integer;
px: PRGB;
al: pbyte;
begin
for row := 0 to Bitmap.Height - 1 do
begin
px := Bitmap.Scanline[row];
al := Bitmap.AlphaChannel.ScanLine[row];
for col := 0 to Bitmap.Width - 1 do
begin
if al^ = 0 then
px^ := CreateRGB(255, 255, 255); // set White when alpha is 0 (transparent pixel)
inc(px);
inc(al);
end;
end;
end;
quote:Can you explain to me, why it works and why it is not the default way?
Load the original image using TImageEnView (ImageEnView1.IO.LoadFromFile('input.png')). Now set ImageEnView.EnableAlphaChannel=false. You will see how actually are "transparent" pixels near the border: they are "black". Sub-resampling does an average (in the simplest algorithm) of a group of pixels, included transparent/black pixels. This is because pixels that should be white, become gray.
I don't use TImageEnView in my image processing unit. I took a look in your source code: The SetAlphaRangePixelsColor procedure manipulates pixels in the IEBitmaps, so is there any reason that SetAlphaRangePixelsColor is a proc of TImageEnView? Can I cut and paste the SetAlphaRangePixelsColor proc in my own code to manipulate my TIEBitmaps? This seems easier as changing my code to use TImageEnView.
I tried to understand why this solution works, but I can't get it... Can you explain to me, why it works and why it is not the default way?
Thank you very much for your help!
Arnd
fab
Posted - Apr 03 2012 : 02:52:13 For performance reasons resampling algorithm takes account also of transparent areas (which are black). You could avoid the gray pixels setting transparent areas to white, for example: