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
 How to maintain image layer transparency?

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
whisper1980 Posted - Jun 05 2021 : 17:33:18
I'd like to compress the ien file. As an example, I have a 54KB jpg image. If I add a small 1K png image layer to it, the merged jpg image stays small at 54KB or so, but the ien layer file is 488KB.

If I reload that large ien layer file, the transparency is retained in the image layer. However, since I save the ien file into a database, it grows too big too fast (my users add and edit lots of images). So, I tried setting the ien compression to JPG, but while small, like a more manageable 69KB small, I lose the image layer transparency.

What is the recommended IEN Compression setting to make the ien file small and still retain he transparency of image layers?

It would be nice, for the ien layers file, to compress the base image in its original format, such as jpg, and the image layers in their original format, such as png. Right now, with no compression, it seems to save as an uncompressed bitmap. Is that right?

ImageEnView1.IO.Params.IEN_Compression := ioJPEG;
ImageEnView1.IO.SaveToFileIEN(fLayerFilename);

ImageEn 10.0.1
Delphi 10.4.2

Eric
15   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Aug 10 2021 : 19:15:46
Hi Eric

You should either remove the alpha channel before loading the background (it will be added back if the image has one) or check whether the alpha channel is used (with a small performance hit). You can do with with AlphaChannel.SyncFull/AlphaChannel.Full. Though in the next update (you can email me for it), just call:

// Discard the alpha channel if not used
ImageEnView1.IEBitmap.HasAlphaChannel( True );




Nigel
Xequte Software
www.imageen.com
whisper1980 Posted - Aug 09 2021 : 17:51:07
Yeah, that's when I saw that I had not updated the DLL when I tried setting the PNGEngine to ieenDLL. :)

I want to keep the background in the original format. Most of the time it is JPG, but might not be, so I don't want to force it to JPG since they might actually be editing a PNG (my interim mods would have messed that up of course, but something I needed to do for that moment).

Eric
xequte Posted - Aug 09 2021 : 17:43:42
Hi Eric

Yes, unfortunately this is an easy error to make. ImageEn tries to be smart and make the best engine decision based on what is available, but it is hard to spot when debugging.

You might want to force the engine to use DLL so it gives an error if the DLL is not valid:

IEGlobalSettings().PNGEngine := ieenDLL;


You will need to call RemoveAlphaChannel() from the background (layer 0) for it to be output with JPEG compression.

Nigel
Xequte Software
www.imageen.com
whisper1980 Posted - Aug 08 2021 : 19:03:30
Ugh! I forgot to update the DLL again! It appears that if I don't have the correct DLL, the ActivePNGEngine defaults to using ieenWIC. When I have the updated DLL available, the ActivePNGEngine uses the ieenDLL and compresses correctly using your suggestion.

BTW, HasAlphaChannel = true (I may have had the png layer selected at the time)

User error, sorry.

Eric
xequte Posted - Aug 07 2021 : 20:22:21
Hi Eric

Hmmm, it is definitely working in my tests.

With a layer with a JPEG background and multiple transparent image layers this gives very different sizes:

  IEGlobalSettings().ThumbnailSize := 0;
  ImageEnView1.IO.Params.IEN_Compression := ioPNG;
  ImageEnView1.IO.SaveToFile( 'D:\Test_PNG.ien' );


  IEGlobalSettings().ThumbnailSize := 0;
  ImageEnView1.IO.Params.IEN_Compression := 10000 + ioPNG;
  ImageEnView1.IO.SaveToFile( 'D:\Test_J+P.ien' );



Can you check:
- ImageEnView1.IEBitmap.HasAlphaChannel = False
- IEGlobalSettings().ActivePNGEngine <> ieenWIC


Also, attach your files you have saved using the two different methods.

Nigel
Xequte Software
www.imageen.com
whisper1980 Posted - Aug 06 2021 : 18:03:30
Unfortunately, this does not work in 10.1.0. The IEN is huge as before. This is my code change you recommended for 10.1.0:
ImageEnView1.IO.Params.IEN_Compression := ioPNG + 10000;
ImageEnView1.IO.SaveToFileIEN(fLayerFilename);
While the PNG layers are transparent, the base layer, which is not transparent, is not being compressed.

I'll have to repeat my mod mentioned earlier to force only the base layer to use the passed in compression format (i.e. ioJPG, which is the merged file format) and let you decide on the other layers:
if i = 0 then
  Layers[i].SaveToStream( Stream, False, CompressionFormat )
else
  Layers[i].SaveToStream( Stream, False, -1 );


Eric
whisper1980 Posted - Jul 05 2021 : 19:58:09
Meant to respond sooner, sorry. That would be fantastic! Thanks!

Eric
xequte Posted - Jun 14 2021 : 20:52:54
Hi Eric

You raise a good point. From 10.0.2 you can offset IEN_Compression by 10000 to use JPEG for non-transparent layers, e.g.

// Use PNG as the compression format for layers with transparency, otherwise use JPEG
ImageEnView1.IO.Params.IEN_Compression := 10000 + ioPNG;
ImageEnView1.IO.SaveToFileIEN('D:\Layers.ien');


Nigel
Xequte Software
www.imageen.com
whisper1980 Posted - Jun 09 2021 : 18:01:37
We use ImageEN for inspectors to add annotations to photos they took in the field. They need to be able to re-edit the images and move previous objects around or delete them, so we keep both the IEN and the merged JPG versions in the database (our old version did not allow that and the #1 complaint was that they couldn't re-edit the added objects like some other image editors allow). A slight loss in one or two re-edits is not a big deal (and never noticed any degradation myself) since the photos are typically just 640x480 and about 3" wide in the PDF report.

Eric
xequte Posted - Jun 09 2021 : 17:51:35
Hi Eric

IEN format is not an "End format", i.e. it is a format used for editing and then once editing is complete a user would output to an end format, e.g. JPEG.

For this reason, I'd be reluctant to use a lossy format like JPEG, as each time the IEN file is saved a bit of the quality would be lost.

Your usage may be different, of course.

Nigel
Xequte Software
www.imageen.com
whisper1980 Posted - Jun 08 2021 : 14:33:45
Actually, this might be better (for me) without needing a new parameter. I pass in the original base image format, e.g. ioJPEG, as my CompressionFormat and modified LayterSaveToStream like this, using internal compression for other layers:
if i = 0 then
  Layers[i].SaveToStream( Stream, False, CompressionFormat )
else
  Layers[i].SaveToStream( Stream, False, -1 );

Eric
whisper1980 Posted - Jun 08 2021 : 14:18:31
Not the best idea, but I tried modifying LayerSaveToStream and it does what I need (small file size and maintains layer transparency), so if you can add a parameter for compression of Layer0 vs other layers, it would be helpful:
if i = 0 then
  Layers[i].SaveToStream( Stream, False, ioJPEG )
else
  Layers[i].SaveToStream( Stream, False, CompressionFormat );


Eric
whisper1980 Posted - Jun 08 2021 : 13:49:42
I also tried the following with no change:
IEGlobalSettings().PNGEngine := ieenNative;

and also tried ieenAuto
whisper1980 Posted - Jun 08 2021 : 13:21:53
Possibly worse. Starting with a 55KB jpg image, adding a 1.6KB PNG image and saving.
ien file with no Compression = 505KB,
ien file with PNG compression = 510KB

After each edit, the merged JPG stayed at 55KB.

Eric
xequte Posted - Jun 07 2021 : 22:09:05
Hi Eric

You should set IEN_Compression to ioPNG for the smallest size with Alpha support.

Note: You cannot use the WIC imaging engine if IEN_Compression=ioPNG as it does not support offset streams.

Nigel
Xequte Software
www.imageen.com