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
 Transparent TIFF
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

dwilbourn

Netherlands
17 Posts

Posted - Oct 01 2022 :  18:50:45  Show Profile  Reply
I want to make a TIFF with a transparent background but I can't work out how. My feeble attempt at some code is:

var
	srcx: PRGBTripleArray;
	destx: pbyte;
	y, x: integer;
begin
        //source image assigned to ImageEnView1.IEBitmap....  
	ImageEnView1.io.Params.TIFF_Compression := ioTIFF_LZW;
	ImageEnView1.io.Params.TIFF_PhotometInterpret := ioTIFF_TRANSPMASK ;

	for y := 0 to ImageEnView1.IEBitmap.Height - 1 do
	begin
		srcx := ImageEnView1.IEBitmap.Scanline[y];
		destx := ImageEnView1.IEBitmap.alphachannel.ScanLine[y];
		for x := 0 to ImageEnView1.IEBitmap.Width - 1 do
		begin
		if  (srcx[x].Red   = GetRValue(TranspColor))
		and (srcx[x].Blue  = GetBValue(TranspColor))
		and (srcx[x].Green = GetGValue(TranspColor)) then
			destx[x] := 0
		else
			destx[x] := 255;
		end;
	end;

	ImageEnView1.IEBitmap.SyncAlphaChannel();
	ImageEnView1.Update;
	ImageEnView1.io.SaveToFileTIFF(Filename);
end;


The Alphachannel looks correct, in that interrogating the pixels[x,y] shows some are 0, some are 255 however something else is obviously wrong as my TIFFs never have a transparent background!

xequte

38127 Posts

Posted - Oct 02 2022 :  22:02:51  Show Profile  Reply
Hi

Most TIFF formats do not support transparency. You are better to use a format like PNG instead:

http://www.imageen.com/help/File_Formats.html

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

dwilbourn

Netherlands
17 Posts

Posted - Oct 03 2022 :  02:33:34  Show Profile  Reply
TIFF does support Transparency via Alpha channel masks though I concede it is very rare, basically an Adobe only feature. However the statement "Transparency Generally NOT supported" on the ImageEn File Formats help page implies that if ImageEn does not support transparency in general, there must be non-general cases where it does. The TIOTIFFPhotometInterpret value of ioTIFF_TRANSPMASK and the TIFF_NewSubfileType value of "Bit 2 is 1 if the image defines a transparency mask for another image in this TIFF file. The PhotometricInterpretation value must be 4, designating a transparency mask." further reinforce that special case interpretation.

My app does produce transparent PNGs. My problem is that the national standards (written by idiots) that govern many of my customers require that they archive images in TIFF with transparency. Which in practice means they have to (buy and) use PhotoShop to open and re-save all the transparent PNGs from my app.
Go to Top of Page

xequte

38127 Posts

Posted - Oct 03 2022 :  21:04:51  Show Profile  Reply
Thanks for clarifying. To preserve the alpha channel in ImageEn, the compression must be set to ioTIFF_UNCOMPRESSED.

Here is an example:

// Save a PNG with alpha to TIFF
ImageEnView1.IO.LoadFromFile( 'D:\Alpha.png' );
ImageEnView1.IEBitmap.PixelFormat             := ie24RGB;
ImageEnView1.IO.Params.TIFF_PhotometInterpret := ioTIFF_RGB;
ImageEnView1.IO.Params.SamplesPerPixel        := 4;
ImageEnView1.IO.Params.BitsPerSample          := 8;
ImageEnView1.IO.Params.TIFF_Compression       := ioTIFF_UNCOMPRESSED;
ImageEnView1.IO.SaveToFile( 'D:\Alpha.TIFF' );

http://www.imageen.com/ieforum/attach/xequte/202210321249_Alpha.TIFF

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

dwilbourn

Netherlands
17 Posts

Posted - Oct 04 2022 :  17:31:20  Show Profile  Reply
It worked! Thank you!!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: