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.
Public Sub ResizeAndSave03(ByVal ImagePath As String, ByVal SavePath As String)
If File.Exists(SavePath) = True Then
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)
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))