ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Incorrect resampling of images with alpha channel?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

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.

I uploaded samples:

www.motionphotos.de/download/IE_Original_Image_WithAlpha.png
www.motionphotos.de/download/IE_Resized_with_IE.png
www.motionphotos.de/download/IE_Resized_with_Photoshop.png

In Photoshop the resizing is done correctly.

Do you have a solution, this is very important to me.

Thank you very much!


Arnd
5   L A T E S T    R E P L I E S    (Newest First)
fab Posted - Apr 22 2012 : 23:32:42
Please could you send both files for tests?
soulmonster Posted - Apr 22 2012 : 23:11:57
Thank you, this works with transparent PNGs perfectly.

It doesn't seem to work, if my Alpha Channel is in a separate file:

ImageIO.LoadFromFile(ImageFilename);
AlphaIO.LoadFromFile(AlphaChannelFilename);
IEAlphaBmp.SwitchTo(ImageIO.AttachedIEBitmap.AlphaChannel);

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.
soulmonster Posted - Apr 03 2012 : 05:02:08
Thank you, this works.

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:
ImageEnView1.IO.LoadFromFile('IE_Original_Image_WithAlpha.png');
ImageEnView1.SetAlphaRangePixelsColor(0, 0, CreateRGB(255,255,255));
ImageEnView1.Proc.Resample(240, 360, rfTriangle);
ImageEnView1.IO.SaveToFile('IE_Resized_with_IE2.png');


CreateRGB is defined in imageenproc unit.