Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2016-08-26
8
90 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

PaperPort is a popular document imaging/management product from Nuance Communications (http://www.nuance.com/). It is in widespread use by both individuals (http://www.nuance.com/for-individuals/by-product/paperport/index.htm) and businesses (http:/…
PaperPort 14.5 Patch 1 update is often not detected or downloaded automatically. This article provides direct download links to solve the problem for retail (non-bundled) versions of the Standard and Professional editions, as well as the Professiona…
In this Micro Tutorial viewers will learn more advanced shortcuts and functions in InDesign.
The goal of the tutorial is to teach the user how to make his/her own presets while editing so it is easier to edit there photos. Create a preset you like and copy that setting then save it in to your presets folder.

792 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