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
 Image does not update

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
PeterPanino Posted - Jun 11 2024 : 17:39:06
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??
2   L A T E S T    R E P L I E S    (Newest First)
PeterPanino Posted - Jun 12 2024 : 03:10:08
It works! Thank you for your support!
xequte Posted - Jun 12 2024 : 00:24:53
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