Solved

Reduce Tiff file size.  Need to set bit dept to 1.

Posted on 2014-03-10
3
424 Views
Last Modified: 2014-03-12
I want to reduce the image of a tiff by about 1/2.  Or maybe I just want to change the DPI from 300 to 96.  Either solution would be fine.  The method below takes a tiff and makes it larger because the bit depth changes from 1 to 32.  It does change the DBI from 300 to 96 and that is desirable.

I have read to use Imaging.PixelFormat.Format1bppIndexed in the constructor, but that creates the exception A Graphics object cannot be created from an image that has an indexed pixel format.

Thank you for your suggestions.


Method 1.
Public Sub ResizeAndSave03(ByVal ImagePath As String, ByVal SavePath As String)

        If File.Exists(SavePath) = True Then
            File.Delete(SavePath)
        End If

        Dim b As New Bitmap(ImagePath)
        Dim Width As Int32 = Convert.ToInt32(b.Width / 2)
        Dim Height As Int32 = Convert.ToInt32(b.Height / 2)
        Dim result As New Bitmap(Width, Height)
        Using g As Graphics = Graphics.FromImage(DirectCast(result, Image))
            'Will throw  - A Graphics object cannot be created from an image that has an indexed pixel format.
            'when this constructor used  Dim result As New Bitmap(Width, Height, Imaging.PixelFormat.Format1bppIndexed)
            g.DrawImage(b, 0, 0, Width, Height)
        End Using
        result.Save(SavePath)
    End Sub

Method 2.

 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim inFile = "test01.tif"
        Dim outFile03 = "outFile03.tif"
        Dim thePath As String = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\files\"
        Dim inImage As String = Path.Combine(thePath, inFile)
              ResizeAndSave03(inImage, Path.Combine(thePath, outFile03))

    End Sub
0
Comment
Question by:wilfordrocks
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
Joe Winograd, EE MVE earned 500 total points
ID: 39918853
My suggestion is to use IrfanView's command line capability. IrfanView is excellent (free!) imaging software that I've been using for many years:
http://www.irfanview.com/

I recommend the Brothersoft link to download IrfanView:
http://www.brothersoft.com/download-irfanview-6224.html

This will download a single install file called <iview437_setup.exe> with no adware and no junk!

And I recommend the Brothersoft link for the PlugIns, which are needed to give you PDF capability:
http://www.brothersoft.com/download-irfanview-all-plugins-164981.html

This will download a single install file called <irfanview_plugins_437_setup.exe> with no adware and no junk!

Install IrfanView first, then install the PlugIns. The PlugIns are optional...only if you want PDF support...and the other features that come with the PlugIns. Although I recommend adding the PlugIns, that's for general, future usage. For this situation, you don't need it, as IrfanView will handle your TIFF files directly.

The IrfanView command line options are documented in a file called <i_options.txt> in the installation folder. I have attached it to this post for your convenience for the latest version of IrfanView, 4.37. In terms of your goal to reduce size, note the following:

(1) The "/tifc" option, which sets the TIFF Compression. Values are:

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

I've done a lot of experimenting with these settings and have found that 4 (ITU-T Group 4) provides the best compression in most cases.

(2) The "/dpi" option, which changes the DPI values.

(3) The "/bpp" option (bits per pixel), which changes the color depth.

If you'd like to see an IrfanView command line call (with TIFF Compression) used in a program, take a look at this article:
http://www.experts-exchange.com/Web_Development/Document_Imaging/A_10745-How-To-Combine-Merge-Append-TIFF-Files-in-Batch-Mode.html

Regards, Joe
IrfanView-4.37-i-options.txt
0
 

Author Closing Comment

by:wilfordrocks
ID: 39924253
Thank you for a very detailed response.
0
 
LVL 52

Expert Comment

by:Joe Winograd, EE MVE
ID: 39924273
You're welcome. Good luck with your project! Regards, Joe
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

919 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now