Solved

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

Posted on 2014-03-10
3
494 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
[X]
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
  • 2
3 Comments
 
LVL 54

Accepted Solution

by:
Joe Winograd, EE MVE 2015&2016 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 54

Expert Comment

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

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

617 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