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
 Image does not update
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

926 Posts

Posted - Jun 11 2024 :  17:39:06  Show Profile  Reply
Use this image:

attach/PeterPanino/2024611173948_NewTestImage.zip
950 Bytes

procedure TForm1.MakeTransparentByLightness(ImageEnView: TImageEnView; Threshold: Integer);
var
  x, y: Integer;
  IEBitmap: TIEBitmap;
  AlphaBitmap: TIEBitmap;
  PixelColor: TRGB;
  Lightness: Integer;
  AlphaScanLine: PByteArray;
begin
  IEBitmap := ImageEnView.IEBitmap; // Reference to the ImageEnView bitmap

  // Ensure the bitmap has an alpha channel
  if not IEBitmap.HasAlphaChannel then
    IEBitmap.AlphaChannel; 

  AlphaBitmap := IEBitmap.AlphaChannel; // Reference the alpha channel bitmap

  // Process each pixel to make those below or above the threshold transparent
  for y := 0 to IEBitmap.Height - 1 do
  begin
    AlphaScanLine := AlphaBitmap.ScanLine[y];
    for x := 0 to IEBitmap.Width - 1 do
    begin
      // Access the pixel color as TRGB
      PixelColor := IEBitmap.Pixels_ie24RGB[x, y];

      // Calculate the Lightness value
      Lightness := PARGBToIntL(PixelColor);

      if Lightness < Threshold then
        AlphaScanLine[x] := 0 // Make pixel fully transparent
      else
        AlphaScanLine[x] := 255; // Make pixel fully opaque
    end;
  end;

  // Ensure the alpha channel is in sync
  IEBitmap.SyncAlphaChannel;

  // Force the component to redraw:
  ImageEnView.Update; // Does NOT update the image!!
end;

procedure TForm1.ButtonLimitImageColorsClick(Sender: TObject);
begin
  MakeTransparentByLightness(ImageEnView1, 300);
end;

function TForm1.PARGBToIntL(ARGB: TRGB): Integer;
// converts TRGB to Integer Luminance value
var
  H, S, L: Double;
begin
  hyieutils.RGB2HSL(ARGB, H, S, L);
  Result := Round(L * 1000);
end;


Why does ImageEnView.Update; not update the image??

xequte

38541 Posts

Posted - Jun 12 2024 :  00:24:53  Show Profile  Reply
Hi Peter

At the end of MakeTransparentByLightness(), please add:
IEBitmap.AlphaChannel.SyncFull();

I'll make this automatic in the next update.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

926 Posts

Posted - Jun 12 2024 :  03:10:08  Show Profile  Reply
It works! Thank you for your support!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: