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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Set all Transparent Pixels in TImageEnView to a specific Opaque Color
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

860 Posts

Posted - Mar 21 2024 :  08:15:09  Show Profile  Reply
I needed to set all Transparent Pixels in a TImageEnView image to a specific Opaque Color:

procedure SetAllTransparentPixelsToOpaqueColor(ImageEnView: imageenview.TImageEnView; AColor: Vcl.Graphics.TColor);
// Set all Transparent Pixels  in TImageEnView to a specific Opaque Color
var
  x, y: Integer;
  ThisBitmap: iexBitmaps.TIEBitmap;
  RGBColor: hyiedefs.TRGB;
begin
  ThisBitmap := ImageEnView.IEBitmap;

  // Optimize performance by locking updates:
  ImageEnView.LockUpdate;
  try
    // Define the RGB color:
    RGBColor := hyieutils.TColor2TRGB(AColor);

    for y := 0 to ThisBitmap.Height - 1 do
    begin
      for x := 0 to ThisBitmap.Width - 1 do
      begin
        if ThisBitmap.Alpha[x, y] < 255 then // if the pixel is not fully opaque
        begin
          // Set the pixel color to the new color and make it fully opaque:
          ThisBitmap.Pixels[x, y] := RGBColor;
          ThisBitmap.Alpha[x, y] := 255; // Set pixel alpha to fully opaque
        end;
      end;
    end;
  finally
    // Ensure updates are unlocked even if an exception occurs:
    ImageEnView.UnlockUpdate;
    ImageEnView.Update;
  end;
end;


Is there a better built-in replacement for this task in ImageEn?

xequte

38182 Posts

Posted - Mar 21 2024 :  19:14:12  Show Profile  Reply
Hi Peter

Yes, you can use RemoveAlphaChannel:

ImageEnView1.IEBitmap.RemoveAlphaChannel( True, clWhite );

https://www.imageen.com/help/TIEBitmap.RemoveAlphaChannel.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: