Solved

Can you suggest a way I can shrink the file size of output image files?

Posted on 2016-08-26
8
96 Views
Last Modified: 2016-08-29
I am developing a C# application using VS2010 and .Net Framework 4.0

I use the following function to combine 2 check image files into 1 check image file with one check image appearing below the other.

However, the output image files created are rather large in file size.

Can you suggest a way I can shrink the size of the output image files and there is a lot of empty space between the 2 check images
in the output check image file.

 public static void ProcessImage(string checkImgPrefix, string directory)
        {
            string tif1 = directory + checkImgPrefix + "_Front.tif";
            string tif2 = directory + checkImgPrefix + "_Rear.tif";
            string tif3 = directory + checkImgPrefix + ".ard.out";

            Image img1 = Image.FromFile(tif1);
            Image img2 = Image.FromFile(tif2);

            int width = Math.Max(img1.Width, img2.Width);
            int height = img1.Height + img2.Height;

            Bitmap img3 = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(img3);

            g.Clear(Color.Black);
            g.DrawImage(img1, new Point(0, 0));
            g.DrawImage(img2, new Point(0, img1.Height));

            g.Dispose();
            img1.Dispose();
            img2.Dispose();

            img3.Save(tif3, System.Drawing.Imaging.ImageFormat.Tiff);
            img3.Dispose();
        }
0
Comment
Question by:zimmer9
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 41772111
Save them as jpgs - that is pretty good at compressing files.
0
 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41772464
Yes, or PNG is good for size reduction (less than JPG) but better quality than JPG.  You could also zip up the 2 source images to reduce the size as well, since you won't need them as they're combined in the final output.
0
 

Author Comment

by:zimmer9
ID: 41773654
I should have noted that I receive the input check image files from the bank in .tif file format and I have no choice in this arrangement.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Expert Comment

by:Joe Winograd, EE MVE
ID: 41773714
> the input check image files from the bank in .tif file format

Uncompressed TIFF files are large, so they are often compressed to make them smaller. I don't know what libraries you are using in your C# app, but if you already have one that does TIFF compression, use it. Otherwise, there are free command line executables out there that you could call from your C# app. For example, although most folks use IrfanView as a GUI imaging app, it also has a command line interface. One of the params in its CLI is /tifc (stands for TIFF Compression) with these choices:

0=None
1=LZW
2=Packbits
3=ITU-T Group 3
4=ITU-T Group 4
5=Huffman
6=JPG
7=ZIP

If it's a one-page TIFF file, this line of code will do it:

i_view32.exe input.tif /convert=output.tif /killmesoftly /silent /tifc=N

Open in new window

where N is an integer from the list above — experiment to see what works for you. If it's a multi-page TIFF file, look at the CLI doc for the /multitif param (the CLI doc is in a file called i_options.txt in the installation folder).

Another possibility is GraphicsMagick or ImageMagick. Here's an EE article that shows how to download/install GM and discusses the various editions:
Reduce the file size of many JPG files in many folders via an automated, mass, batch compression method

It also shows how to shrink the file size of JPG files, although the -quality option doesn't work for TIFF files. Instead, use the -compress option:

-compress TYPE

where the choices for TYPE are:

None
BZip
Fax
Group4
JPEG
Lossless
LZW
RLE
Zip
LZMA

Note that +compress makes the output file uncompressed. Also note that Lossless is just for lossless JPEG, so does not apply to TIFF files (all of the command line params are documented at http://www.graphicsmagick.org/GraphicsMagick.html).

To convert and modify the source file directly, use the mogrify sub-command, something like:

gm mogrify -compress Group4 input.tif

Open in new window

To convert and store the compressed file in a new file, use the convert sub-command, something like:

gm convert input.tif -compress Group4 output.tif

Open in new window


I just tested GM with a 50 MB uncompressed TIFF file — shrank it to a 96 KB TIFF file with Group4 compression! ImageMagick also supports the same convert and mogrify functions. Regards, Joe
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 41773768
If you have no choice about the file type (from a third party) you might not be able to compress them and still have the third party be able to use them.
0
 

Author Comment

by:zimmer9
ID: 41773780
The files will be sent to IBM Content Manager OnDemand for viewing.
0
 
LVL 53

Expert Comment

by:Joe Winograd, EE MVE
ID: 41773787
Given that check images from the bank are likely black&white (even if the actual checks are color), I suggest ITU-T (formerly CCITT) Group 4 compression, which should work very well on them, resulting in a significant reduction of the file size. And third-party software should certainly be able to use a TIFF file with Group 4 compression, which has been an industry standard for decades. Regards, Joe
0
 
LVL 53

Accepted Solution

by:
Joe Winograd, EE MVE earned 500 total points
ID: 41773788
Our messages just crossed — the IBM Content Manager should have no problem viewing a TIFF file with Group 4 compression — try it.

Update: I'm not familiar with .NET code, but here's a question where the asker has calls to Group 4 compression:
https://www.experts-exchange.com/questions/28966186/why-Created-tiff-files-are-coming-in-huge-size.html

I'm guessing he got the code from elsewhere and doesn't even realize that the Group 4 compression code has been commented out (hence, my post there). But if that code is good, it should work in your C# app. Look at these commented out lines that appear to be calling CCITT Group 4 compression:

' iparamPara = New EncoderParameter(iparam, CLng(EncoderValue.CompressionCCITT4))

' CompressionEncodeParam = new EncoderParameter(compressionEncoder, (long)EncoderValue.CompressionCCITT4);

' EncoderParams.Param(1) = New EncoderParameter(System.Drawing.Imaging.Encoder.Compression, EncoderValue.CompressionCCITT4)

' myEncoderParameters.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionCCITT4);

' CompressionEncodeParam = new EncoderParameter(compressionEncoder, (long)EncoderValue.CompressionCCITT4);

Open in new window

Regards, Joe
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tableview is not updating 1 28
How to use spatial data types in SQL Server Database project 2 41
Upgrade code from VS 2010 to VS 2015 7 32
How to force output to ascii 2 34
I. Introduction In a previous article (http://www.experts-exchange.com/Web_Development/Document_Imaging/A_6537-PaperPort-Upgrade-How-to-download-and-install-updated-versions-of-PaperPort-11-and-12.html) (now deprecated), I discussed how to upgrad…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Users will learn how resize a batch of photos from a single command in Photoshop via Photoshop's Image Processor. Open up an Image you'd like to resize in Adobe Photoshop: Adjust the image size according to your preferences. Image > Adjustments > …
In this Micro Tutorial viewers will learn the basic shortcuts and functions in InDesign.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question