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
 TImageEnView : Paint on transparent pixels
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

esprd

10 Posts

Posted - Jul 07 2025 :  13:31:37  Show Profile  Reply
Hello,
I have an image with 2 layers.
Layer 1 is a png black and blue, with clBlue as transparent color. The blue pixels are a kind of mask above my background, and the black darken the background (layer semi-transparent).
I want to change some "blue zones" (I have a list of pixels) into black.
But it seems that setting a color on a transparent zone has no effect.

My code :

procedure displayPicture( APictFileName, ALayerFileName : string ) ;
begin
  // Load background
  ImageEnView1.IO.LoadFromFile( APictFileName ) ;

  // Load layer
  ImageEnView1.LayersAdd(ImageEnView1.Layers[0].Kind,
                      ImageEnView1.Layers[0].PosX,
                      ImageEnView1.Layers[0].PosY,
                      ImageEnView1.Layers[0].Width,
                      ImageEnView1.Layers[0].Height) // Append a new layer


  ImageEnView1.IO.LoadFromFile( ALayerFileName ) ;

  // Set transparency
  ImageEnView1.IO.IEBitmap.SetTransparentColors( clBlue, clBlue, 0 ) ;
  ImageEnView1.Layers[1].Opacity := 0.7 ;
  
end ;


procedure UpdateDisplay( XList, YList : TIntegerlist ) ;
// Remove Pixels from "blue" transparent area, set them black, called after some user actions
var
  i : integer ;

begin

  for i := 0 to XList.Count - 1 do
    ImageEnView1.Layers[LayerIdx].Bitmap.Pixels[XList[i], YList[i]] := TColor2TRGB( clBlack ) ;

end ;

The workaround I found is to write this :

  // Reset transparency
  ImageEnView1.LayersCurrent := 1 ;
  ImageEnView1.IO.IEBitmap.SetTransparentColors( clBlue, clBlue, 255 ) ;

  for i := 0 to XList.Count - 1 do
    ImageEnView1.Layers[LayerIdx].Bitmap.Pixels[XList[i], YList[i]] := TColor2TRGB( clBlack ) ;

  ImageEnView1.IO.IEBitmap.SetTransparentColors( clBlue, clBlue, 0 ) ;

xequte

39097 Posts

Posted - Jul 08 2025 :  04:17:06  Show Profile  Reply
Hi

Don't forget that if a pixel has been set as transparent (i.e. the pixel in the AlphaChannel has value 0) then setting the pixel in the image channel has no effect (even though the color has changed, it is still transparent).

So ensure you set the image and alpha channel pixel, e.g.

ImageEnView1.Layers[LayerIdx].Bitmap.Pixels[ x, y ] := TColor2TRGB( clBlack );
ImageEnView1.Layers[LayerIdx].Bitmap.AlphaChannel.Pixels_ie8[ x, y ] := 255;  // Make the pixel opaque

Please see:

http://www.imageen.com/help/TIEBitmap.AlphaChannel.html

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

esprd

10 Posts

Posted - Jul 08 2025 :  13:17:53  Show Profile  Reply
Ok thank you.
It's working with
ImageEnView1.Layers[LayerIdx].Bitmap.Alpha[ x, y ] := 255; // Make the pixel opaque

(building error with ImageEnView1.Layers[LayerIdx].Bitmap.AlphaChannel.Pixels[ x, y ] := 255; )

ep
Go to Top of Page

xequte

39097 Posts

Posted - Jul 08 2025 :  21:21:38  Show Profile  Reply
Sorry, that should have read "Pixels_ie8" rather than just "Pixels" (because the alpha channel is a ie8g image)

But setting Alpha[ x, y ] := ...; is actually better anyway (copes also with RGBA).

Please note though that accessing Pixels directly is much slower than using ScanLines, so if performance is needed, use that instead:

http://www.imageen.com/help/TIEBitmap.Scanline.html

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