Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-03-10
3
Medium Priority
?
515 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 55

Accepted Solution

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

Expert Comment

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

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

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…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

704 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