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
 Creating a "lighter" version of an heavy image.
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

mastinf

Italy
46 Posts

Posted - Apr 15 2016 :  09:34:32  Show Profile  Reply
hello,

in my application i have some reports where i have a lot of images.
Images can be heavy. the results is that the reports creation time can be high. I was thinking, in the acquisition process of the images, to save two versions: an high quality one and a lighter one (i'll use one or the other as requred by situation).
I see there's a resample method in TImageEnProc, but in this way the size of the image will be reduced. I don't want this. I want the size in inches (pixels divided by DPI) remains the same. Is there a specific ImageEn method (or some Delphi code) that you can share with me ?

thanks

Roberto

Roberto Nicchi
Master Informatica
Italy

w2m

USA
1990 Posts

Posted - Apr 15 2016 :  11:15:21  Show Profile  Reply
The answer to your question depends on the file types you choose and the quality needed. It is not a simple question to answer. The most effective way to reduce file size is to resample the image to smaller dimensions. Having said that, the next most effective parameters are the file type, the bit depth and the compression level, JPEG Quality or PNG_Compression. Png images and jpeg images are probably the best. Bit depths of 256 color may help reduce file size.

You will have to experiment with these parameters to see what the result is to produce the smallest files with the highest quality.
// Sets color-mapped 256 colors
ImageEnView1.IO.Params.BitsPerSample := 8;
ImageEnView1.IO.Params.SamplesPerPixel := 1;

// Sets JPEG quality of 70% 
ImageEnView1.IO.Params.JPEG_Quality := 70;
ImageEnView1.IO.SaveToFile('D:\output.jpg');

If your images are jpeg, then reduce the Jpeg quality to a level that produces the results that are needed for your use and display of the images in your application. If 256 color images are not acceptable then use 24-bit.
ImageEnView1.IO.Params.BitsPerSample := 8;
ImageEnView1.IO.Params.SamplesPerPixel := 3;

The file size probably will be larger with 24-bit but only you can decide on the quality of the image you need.

If your files are PNG then experiment with PNG Compression. (iexBitmaps.pas)
ImageEnView1.IO.Params.PNG_Compression := 9;

See the help file in IO.Params for the various parameters that can be set depending on the file type.

An alternative to consider is using TImageEnMView to display thumbnails of jpg images, by using a StoreType property of ietFastThumb or ietThumb. The default is ietNormal which does not use thumbnails but require more time for loading. Then if you need to display the entire original image, load the file into TImageEnView using the filename stored in the ImageEnMView1.MIO.Params[x].Filename parameter. When the StoreType peoperty is set to ietFastThumb or ietThumb if you load the image into TImageEnView, the quality and the size of the image will be poor. That way you can have both fast loading of images (thumbnails) and still have access the full original image from the filename.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

rmklever

Norway
52 Posts

Posted - Apr 17 2016 :  11:34:09  Show Profile  Reply
Hi Roberto,

what do you mean by heavy and light image? If you save an image in png and use 20MB or you save the same picture as a jpeg file using 200kB it will still use the same amount of memory when loaded back into memory.

The only option I see that might be of use is to convert it into 256 colors, but if the report generator convert every image into 24 bit it will not make any difference.

There are not enough information in your post too come up with a good answear.


Roy M Klever
Klever on Delphi - www.rmklever.com
Go to Top of Page

xequte

39053 Posts

Posted - Apr 17 2016 :  16:13:20  Show Profile  Reply
Hi Roberto

It is true that if you halve the size of an image but double its DPI then print it, theoretically both images would print at the same size (but one with less quality). But the image is still half the size. DPI is generally only relevant when printing, and should only be thought of as advice for how an image should be scaled (for example, doubling the DPI of an image, should give the same effect as printing at 200% size).

Anyway, to handle this in MLK, you can resample the image and then set new DPI values, or you can call ChangeResolution():

http://www.imageen.com/help/TImageEnView.ChangeResolution.html

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

mastinf

Italy
46 Posts

Posted - Apr 18 2016 :  03:19:12  Show Profile  Reply
Hello, thanks for all your suggestions.
Images are in JPG format / 24bit colors.
As rmklever said it's not really important the space used on disk.
It's important the space used in memory. Less image is used and less the elaborations on images will be faster. A report with many images will (i suppose) use less total memory and will be created in a shorter time. The ChangeResolution suggested by xequte could be a solution.
I'm experimenting.

thanks

Roberto Nicchi
Master Informatica
Italy
Go to Top of Page

mastinf

Italy
46 Posts

Posted - Apr 18 2016 :  05:15:46  Show Profile  Reply
After a bit of coding i have decided to use the resample method recalculating manually the new DPI to avoid the image's size in inches is changed. It seems working.
The last ting that i have to solve is: when i have to resample ? Images are not all the same. Some could be heavy (maybe taken with a digital camera). Others could be low res so i don't have to resample. My first tought was to consider the megapixels. If the image is larger that a a predefinied megapixel value i will resample... I'm open to any suggestion. thanks

Roberto Nicchi
Master Informatica
Italy
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: