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

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

Posted on 2014-03-10
3
449 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 53

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 53

Expert Comment

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

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display

856 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