HighTechTalks DotNet Forums  

TIFF Creation Issues...

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss TIFF Creation Issues... in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Doug
 
Posts: n/a

Default TIFF Creation Issues... - 03-16-2007 , 09:49 AM






I have a small application that reads a multipage TIFF (thanks Bob Powell!)
and then simply rewrites the pages to a new TIFF file. It doesn't do
anything to it except extract the pages and then reassemble them into a new
file. The problem is that the new file is 778kb and the old file was only
58kb. In addition, the new images are rotated 90 degrees and occupies only
the left half of the page.

The code I use to extract the images is:

Dim fs As FileStream = File.Open(f, FileMode.Open, FileAccess.Read)
Dim bm As Bitmap = CType(Bitmap.FromStream(fs), Bitmap)

If bm.GetFrameCount(FrameDimension.Page) > 1 Then
Dim i As Integer
For i = 0 To (bm.GetFrameCount(FrameDimension.Page)) - 1
bm.SelectActiveFrame(FrameDimension.Page, i)
Dim temp As New Bitmap(bm.Width, bm.Height)
Dim g As Graphics = Graphics.FromImage(temp)
g.InterpolationMode = InterpolationMode.NearestNeighbor
g.DrawImageUnscaled(bm, 0, 0)
g.Dispose()
AddFrameToList(temp, -1)
Next i
Else
AddFrameToList(bm, 0)
End If
fs.Close()
bm.Dispose()

The code to reassemble them into a new image is:

If L.Count > 1 Then
'the first item in the list is the master frame.
Dim ii As ImageItem = CType(L(0), ImageItem)
Dim MasterBitmap As Bitmap = CType(ii.Image, Bitmap)
Dim f2 As String = Path.GetDirectoryName(f) + "\Processing.tmp"

'Select the image encoder
Dim enc As Encoder = Encoder.SaveFlag
Dim info As ImageCodecInfo = Nothing

Dim ice As ImageCodecInfo
For Each ice In ImageCodecInfo.GetImageEncoders()
If ice.MimeType = "image/tiff" Then
info = ice
End If
Next ice
Dim ep As New EncoderParameters(1)

ep.Param(0) = New EncoderParameter(enc,
CLng(EncoderValue.MultiFrame))

'Save the master bitmap
MasterBitmap.Save(f2, info, ep)

ep.Param(0) = New EncoderParameter(enc,
CLng(EncoderValue.FrameDimensionPage))

'add all images from index 1 to n
Dim i As Integer
For i = 1 To (L.Count) - 1
ii = CType(L(i), ImageItem)
MasterBitmap.SaveAdd(ii.Image, ep)
Next i
ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.Flush))
'close out the file.
MasterBitmap.SaveAdd(ep)
File.Move(f2, f)
Try
File.Delete(f2)
Catch ex As Exception
End Try
Else
'do a simple save...
CType(L(0), ImageItem).Image.Save(f, ImageFormat.Tiff)
End If


Please remember that this code was gleaned from various sources (mostly Bob
Powell's excellent tutorials on GDI+!) so I don't claim to understand it all.
Any assistance in getting the new image to be the same orientation and size
as the old image would be GREATLY appreciated...

<background>
You may wonder why I'm simply reading an image and rewriting it to another
image... Good question. The project I'm working on is to take inbound
Purchase orders that are faxed and convert them to EDI documents for
importing into our order entry system. The images are run through OCR
software to produce a text file that is scanned for various pieces of
information and then written to an XML file for import. Unfortunately, some
of the images that get written from our network fax server contain some sort
of anomoly in the data that keeps it from being read by the OCR package
(Omnipage). Even Photoshop cannot read the images. Windows picture & fax
view will display and print them, though. I stumbled on the thought of
reading & rewriting the image to see if VB could read it. Lo and behold, the
OCR software can read the newly created file!!! Now I'm trying to work with
multipage images and having the above problems. Sorry for the length but I
felt that more background was better than none.
</background>

Reply With Quote
  #2  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: TIFF Creation Issues... - 03-16-2007 , 10:13 AM






This sounds to me like an issue with the original file.

Can you send me one?

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





Doug wrote:
Quote:
I have a small application that reads a multipage TIFF (thanks Bob Powell!)
and then simply rewrites the pages to a new TIFF file. It doesn't do
anything to it except extract the pages and then reassemble them into a new
file. The problem is that the new file is 778kb and the old file was only
58kb. In addition, the new images are rotated 90 degrees and occupies only
the left half of the page.

The code I use to extract the images is:

Dim fs As FileStream = File.Open(f, FileMode.Open, FileAccess.Read)
Dim bm As Bitmap = CType(Bitmap.FromStream(fs), Bitmap)

If bm.GetFrameCount(FrameDimension.Page) > 1 Then
Dim i As Integer
For i = 0 To (bm.GetFrameCount(FrameDimension.Page)) - 1
bm.SelectActiveFrame(FrameDimension.Page, i)
Dim temp As New Bitmap(bm.Width, bm.Height)
Dim g As Graphics = Graphics.FromImage(temp)
g.InterpolationMode = InterpolationMode.NearestNeighbor
g.DrawImageUnscaled(bm, 0, 0)
g.Dispose()
AddFrameToList(temp, -1)
Next i
Else
AddFrameToList(bm, 0)
End If
fs.Close()
bm.Dispose()

The code to reassemble them into a new image is:

If L.Count > 1 Then
'the first item in the list is the master frame.
Dim ii As ImageItem = CType(L(0), ImageItem)
Dim MasterBitmap As Bitmap = CType(ii.Image, Bitmap)
Dim f2 As String = Path.GetDirectoryName(f) + "\Processing.tmp"

'Select the image encoder
Dim enc As Encoder = Encoder.SaveFlag
Dim info As ImageCodecInfo = Nothing

Dim ice As ImageCodecInfo
For Each ice In ImageCodecInfo.GetImageEncoders()
If ice.MimeType = "image/tiff" Then
info = ice
End If
Next ice
Dim ep As New EncoderParameters(1)

ep.Param(0) = New EncoderParameter(enc,
CLng(EncoderValue.MultiFrame))

'Save the master bitmap
MasterBitmap.Save(f2, info, ep)

ep.Param(0) = New EncoderParameter(enc,
CLng(EncoderValue.FrameDimensionPage))

'add all images from index 1 to n
Dim i As Integer
For i = 1 To (L.Count) - 1
ii = CType(L(i), ImageItem)
MasterBitmap.SaveAdd(ii.Image, ep)
Next i
ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.Flush))
'close out the file.
MasterBitmap.SaveAdd(ep)
File.Move(f2, f)
Try
File.Delete(f2)
Catch ex As Exception
End Try
Else
'do a simple save...
CType(L(0), ImageItem).Image.Save(f, ImageFormat.Tiff)
End If


Please remember that this code was gleaned from various sources (mostly Bob
Powell's excellent tutorials on GDI+!) so I don't claim to understand it all.
Any assistance in getting the new image to be the same orientation and size
as the old image would be GREATLY appreciated...

background
You may wonder why I'm simply reading an image and rewriting it to another
image... Good question. The project I'm working on is to take inbound
Purchase orders that are faxed and convert them to EDI documents for
importing into our order entry system. The images are run through OCR
software to produce a text file that is scanned for various pieces of
information and then written to an XML file for import. Unfortunately, some
of the images that get written from our network fax server contain some sort
of anomoly in the data that keeps it from being read by the OCR package
(Omnipage). Even Photoshop cannot read the images. Windows picture & fax
view will display and print them, though. I stumbled on the thought of
reading & rewriting the image to see if VB could read it. Lo and behold, the
OCR software can read the newly created file!!! Now I'm trying to work with
multipage images and having the above problems. Sorry for the length but I
felt that more background was better than none.
/background

Reply With Quote
  #3  
Old   
Doug
 
Posts: n/a

Default Re: TIFF Creation Issues... - 03-16-2007 , 11:25 AM



Sure. I assume your address is correct (without the _spamkiller_)...

Doug


"Bob Powell [MVP]" wrote:

Quote:
This sounds to me like an issue with the original file.

Can you send me one?

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





Doug wrote:
I have a small application that reads a multipage TIFF (thanks Bob Powell!)
and then simply rewrites the pages to a new TIFF file. It doesn't do
anything to it except extract the pages and then reassemble them into a new
file. The problem is that the new file is 778kb and the old file was only
58kb. In addition, the new images are rotated 90 degrees and occupies only
the left half of the page.

The code I use to extract the images is:

Dim fs As FileStream = File.Open(f, FileMode.Open, FileAccess.Read)
Dim bm As Bitmap = CType(Bitmap.FromStream(fs), Bitmap)

If bm.GetFrameCount(FrameDimension.Page) > 1 Then
Dim i As Integer
For i = 0 To (bm.GetFrameCount(FrameDimension.Page)) - 1
bm.SelectActiveFrame(FrameDimension.Page, i)
Dim temp As New Bitmap(bm.Width, bm.Height)
Dim g As Graphics = Graphics.FromImage(temp)
g.InterpolationMode = InterpolationMode.NearestNeighbor
g.DrawImageUnscaled(bm, 0, 0)
g.Dispose()
AddFrameToList(temp, -1)
Next i
Else
AddFrameToList(bm, 0)
End If
fs.Close()
bm.Dispose()

The code to reassemble them into a new image is:

If L.Count > 1 Then
'the first item in the list is the master frame.
Dim ii As ImageItem = CType(L(0), ImageItem)
Dim MasterBitmap As Bitmap = CType(ii.Image, Bitmap)
Dim f2 As String = Path.GetDirectoryName(f) + "\Processing.tmp"

'Select the image encoder
Dim enc As Encoder = Encoder.SaveFlag
Dim info As ImageCodecInfo = Nothing

Dim ice As ImageCodecInfo
For Each ice In ImageCodecInfo.GetImageEncoders()
If ice.MimeType = "image/tiff" Then
info = ice
End If
Next ice
Dim ep As New EncoderParameters(1)

ep.Param(0) = New EncoderParameter(enc,
CLng(EncoderValue.MultiFrame))

'Save the master bitmap
MasterBitmap.Save(f2, info, ep)

ep.Param(0) = New EncoderParameter(enc,
CLng(EncoderValue.FrameDimensionPage))

'add all images from index 1 to n
Dim i As Integer
For i = 1 To (L.Count) - 1
ii = CType(L(i), ImageItem)
MasterBitmap.SaveAdd(ii.Image, ep)
Next i
ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.Flush))
'close out the file.
MasterBitmap.SaveAdd(ep)
File.Move(f2, f)
Try
File.Delete(f2)
Catch ex As Exception
End Try
Else
'do a simple save...
CType(L(0), ImageItem).Image.Save(f, ImageFormat.Tiff)
End If


Please remember that this code was gleaned from various sources (mostly Bob
Powell's excellent tutorials on GDI+!) so I don't claim to understand it all.
Any assistance in getting the new image to be the same orientation and size
as the old image would be GREATLY appreciated...

background
You may wonder why I'm simply reading an image and rewriting it to another
image... Good question. The project I'm working on is to take inbound
Purchase orders that are faxed and convert them to EDI documents for
importing into our order entry system. The images are run through OCR
software to produce a text file that is scanned for various pieces of
information and then written to an XML file for import. Unfortunately, some
of the images that get written from our network fax server contain some sort
of anomoly in the data that keeps it from being read by the OCR package
(Omnipage). Even Photoshop cannot read the images. Windows picture & fax
view will display and print them, though. I stumbled on the thought of
reading & rewriting the image to see if VB could read it. Lo and behold, the
OCR software can read the newly created file!!! Now I'm trying to work with
multipage images and having the above problems. Sorry for the length but I
felt that more background was better than none.
/background


Reply With Quote
  #4  
Old   
Glen M
 
Posts: n/a

Default Re: TIFF Creation Issues... - 05-11-2007 , 09:08 AM



Was this figured out? I have a similar problem. I have a 9 page multi-page
tiff which I am pulling out a couple pages and saving to a new 4 page
multipage tiff. This first page is the same as the original. The remaining 3
are much smaller. I am using the MS standard viewer to validate the tiff is
good. In the MS viewer all the pages are the same size. I have tried it with
different source Tiffs. Here is my code:

This is just for a prototype. The final product will be more dynamic.
I first split the source tiff:

pictureBox1.Image.SelectActiveFrame(FrameDimension .Page, 0);
pictureBox2.Image = (Image)pictureBox1.Image.Clone();

pictureBox1.Image.SelectActiveFrame(FrameDimension .Page, 1);
pictureBox3.Image = (Image)pictureBox1.Image.Clone();

pictureBox1.Image.SelectActiveFrame(FrameDimension .Page, 2);
pictureBox4.Image = (Image)pictureBox1.Image.Clone();

pictureBox1.Image.SelectActiveFrame(FrameDimension .Page, 3);
pictureBox5.Image = (Image)pictureBox1.Image.Clone();

Next I save it to a new tiff:

Bitmap bmp = new Bitmap(pictureBox2.Image);

ImageCodecInfo ici = GetEncoderCodec("image/tiff");

System.Drawing.Imaging.EncoderParameters eps = new EncoderParameters(2);
eps.Param[0] = new
EncoderParameter(System.Drawing.Imaging.Encoder.Co mpression,
(long)EncoderValue.CompressionLZW);
eps.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Sa veFlag,
(long)EncoderValue.MultiFrame);

bmp.Save("c:\\test.tif", ici, eps);

eps.Param[0] = new
EncoderParameter(System.Drawing.Imaging.Encoder.Co mpression,
(long)EncoderValue.CompressionLZW);
eps.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Sa veFlag,
(long)EncoderValue.FrameDimensionPage);

bmp.SaveAdd(pictureBox3.Image, eps);
bmp.SaveAdd(pictureBox4.Image, eps);
bmp.SaveAdd(pictureBox5.Image, eps);

eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Sa veFlag,
(long)EncoderValue.Flush);
bmp.SaveAdd(eps);

Any help/direction would be appreciated.

Thanks, Glen

"Doug" wrote:

Quote:
Sure. I assume your address is correct (without the _spamkiller_)...

Doug


"Bob Powell [MVP]" wrote:

This sounds to me like an issue with the original file.

Can you send me one?

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





Doug wrote:
I have a small application that reads a multipage TIFF (thanks Bob Powell!)
and then simply rewrites the pages to a new TIFF file. It doesn't do
anything to it except extract the pages and then reassemble them into a new
file. The problem is that the new file is 778kb and the old file was only
58kb. In addition, the new images are rotated 90 degrees and occupies only
the left half of the page.

The code I use to extract the images is:

Dim fs As FileStream = File.Open(f, FileMode.Open, FileAccess.Read)
Dim bm As Bitmap = CType(Bitmap.FromStream(fs), Bitmap)

If bm.GetFrameCount(FrameDimension.Page) > 1 Then
Dim i As Integer
For i = 0 To (bm.GetFrameCount(FrameDimension.Page)) - 1
bm.SelectActiveFrame(FrameDimension.Page, i)
Dim temp As New Bitmap(bm.Width, bm.Height)
Dim g As Graphics = Graphics.FromImage(temp)
g.InterpolationMode = InterpolationMode.NearestNeighbor
g.DrawImageUnscaled(bm, 0, 0)
g.Dispose()
AddFrameToList(temp, -1)
Next i
Else
AddFrameToList(bm, 0)
End If
fs.Close()
bm.Dispose()

The code to reassemble them into a new image is:

If L.Count > 1 Then
'the first item in the list is the master frame.
Dim ii As ImageItem = CType(L(0), ImageItem)
Dim MasterBitmap As Bitmap = CType(ii.Image, Bitmap)
Dim f2 As String = Path.GetDirectoryName(f) + "\Processing.tmp"

'Select the image encoder
Dim enc As Encoder = Encoder.SaveFlag
Dim info As ImageCodecInfo = Nothing

Dim ice As ImageCodecInfo
For Each ice In ImageCodecInfo.GetImageEncoders()
If ice.MimeType = "image/tiff" Then
info = ice
End If
Next ice
Dim ep As New EncoderParameters(1)

ep.Param(0) = New EncoderParameter(enc,
CLng(EncoderValue.MultiFrame))

'Save the master bitmap
MasterBitmap.Save(f2, info, ep)

ep.Param(0) = New EncoderParameter(enc,
CLng(EncoderValue.FrameDimensionPage))

'add all images from index 1 to n
Dim i As Integer
For i = 1 To (L.Count) - 1
ii = CType(L(i), ImageItem)
MasterBitmap.SaveAdd(ii.Image, ep)
Next i
ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.Flush))
'close out the file.
MasterBitmap.SaveAdd(ep)
File.Move(f2, f)
Try
File.Delete(f2)
Catch ex As Exception
End Try
Else
'do a simple save...
CType(L(0), ImageItem).Image.Save(f, ImageFormat.Tiff)
End If


Please remember that this code was gleaned from various sources (mostly Bob
Powell's excellent tutorials on GDI+!) so I don't claim to understand it all.
Any assistance in getting the new image to be the same orientation and size
as the old image would be GREATLY appreciated...

background
You may wonder why I'm simply reading an image and rewriting it to another
image... Good question. The project I'm working on is to take inbound
Purchase orders that are faxed and convert them to EDI documents for
importing into our order entry system. The images are run through OCR
software to produce a text file that is scanned for various pieces of
information and then written to an XML file for import. Unfortunately, some
of the images that get written from our network fax server contain some sort
of anomoly in the data that keeps it from being read by the OCR package
(Omnipage). Even Photoshop cannot read the images. Windows picture & fax
view will display and print them, though. I stumbled on the thought of
reading & rewriting the image to see if VB could read it. Lo and behold, the
OCR software can read the newly created file!!! Now I'm trying to work with
multipage images and having the above problems. Sorry for the length but I
felt that more background was better than none.
/background


Reply With Quote
  #5  
Old   
Glen M
 
Posts: n/a

Default Re: TIFF Creation Issues... - 05-11-2007 , 11:22 AM



I figured out my problem. When I saved to the new Tiff I was creating a new
Bitmap which was the default 32bpp pixel format. I just created a var
pointing to the picturebox2 image and all is well.

"Glen M" wrote:

Quote:
Was this figured out? I have a similar problem. I have a 9 page multi-page
tiff which I am pulling out a couple pages and saving to a new 4 page
multipage tiff. This first page is the same as the original. The remaining 3
are much smaller. I am using the MS standard viewer to validate the tiff is
good. In the MS viewer all the pages are the same size. I have tried it with
different source Tiffs. Here is my code:

This is just for a prototype. The final product will be more dynamic.
I first split the source tiff:

pictureBox1.Image.SelectActiveFrame(FrameDimension .Page, 0);
pictureBox2.Image = (Image)pictureBox1.Image.Clone();

pictureBox1.Image.SelectActiveFrame(FrameDimension .Page, 1);
pictureBox3.Image = (Image)pictureBox1.Image.Clone();

pictureBox1.Image.SelectActiveFrame(FrameDimension .Page, 2);
pictureBox4.Image = (Image)pictureBox1.Image.Clone();

pictureBox1.Image.SelectActiveFrame(FrameDimension .Page, 3);
pictureBox5.Image = (Image)pictureBox1.Image.Clone();

Next I save it to a new tiff:

Bitmap bmp = new Bitmap(pictureBox2.Image);

ImageCodecInfo ici = GetEncoderCodec("image/tiff");

System.Drawing.Imaging.EncoderParameters eps = new EncoderParameters(2);
eps.Param[0] = new
EncoderParameter(System.Drawing.Imaging.Encoder.Co mpression,
(long)EncoderValue.CompressionLZW);
eps.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Sa veFlag,
(long)EncoderValue.MultiFrame);

bmp.Save("c:\\test.tif", ici, eps);

eps.Param[0] = new
EncoderParameter(System.Drawing.Imaging.Encoder.Co mpression,
(long)EncoderValue.CompressionLZW);
eps.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Sa veFlag,
(long)EncoderValue.FrameDimensionPage);

bmp.SaveAdd(pictureBox3.Image, eps);
bmp.SaveAdd(pictureBox4.Image, eps);
bmp.SaveAdd(pictureBox5.Image, eps);

eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Sa veFlag,
(long)EncoderValue.Flush);
bmp.SaveAdd(eps);

Any help/direction would be appreciated.

Thanks, Glen

"Doug" wrote:

Sure. I assume your address is correct (without the _spamkiller_)...

Doug


"Bob Powell [MVP]" wrote:

This sounds to me like an issue with the original file.

Can you send me one?

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





Doug wrote:
I have a small application that reads a multipage TIFF (thanks Bob Powell!)
and then simply rewrites the pages to a new TIFF file. It doesn't do
anything to it except extract the pages and then reassemble them into a new
file. The problem is that the new file is 778kb and the old file was only
58kb. In addition, the new images are rotated 90 degrees and occupies only
the left half of the page.

The code I use to extract the images is:

Dim fs As FileStream = File.Open(f, FileMode.Open, FileAccess.Read)
Dim bm As Bitmap = CType(Bitmap.FromStream(fs), Bitmap)

If bm.GetFrameCount(FrameDimension.Page) > 1 Then
Dim i As Integer
For i = 0 To (bm.GetFrameCount(FrameDimension.Page)) - 1
bm.SelectActiveFrame(FrameDimension.Page, i)
Dim temp As New Bitmap(bm.Width, bm.Height)
Dim g As Graphics = Graphics.FromImage(temp)
g.InterpolationMode = InterpolationMode.NearestNeighbor
g.DrawImageUnscaled(bm, 0, 0)
g.Dispose()
AddFrameToList(temp, -1)
Next i
Else
AddFrameToList(bm, 0)
End If
fs.Close()
bm.Dispose()

The code to reassemble them into a new image is:

If L.Count > 1 Then
'the first item in the list is the master frame.
Dim ii As ImageItem = CType(L(0), ImageItem)
Dim MasterBitmap As Bitmap = CType(ii.Image, Bitmap)
Dim f2 As String = Path.GetDirectoryName(f) + "\Processing.tmp"

'Select the image encoder
Dim enc As Encoder = Encoder.SaveFlag
Dim info As ImageCodecInfo = Nothing

Dim ice As ImageCodecInfo
For Each ice In ImageCodecInfo.GetImageEncoders()
If ice.MimeType = "image/tiff" Then
info = ice
End If
Next ice
Dim ep As New EncoderParameters(1)

ep.Param(0) = New EncoderParameter(enc,
CLng(EncoderValue.MultiFrame))

'Save the master bitmap
MasterBitmap.Save(f2, info, ep)

ep.Param(0) = New EncoderParameter(enc,
CLng(EncoderValue.FrameDimensionPage))

'add all images from index 1 to n
Dim i As Integer
For i = 1 To (L.Count) - 1
ii = CType(L(i), ImageItem)
MasterBitmap.SaveAdd(ii.Image, ep)
Next i
ep.Param(0) = New EncoderParameter(enc, CLng(EncoderValue.Flush))
'close out the file.
MasterBitmap.SaveAdd(ep)
File.Move(f2, f)
Try
File.Delete(f2)
Catch ex As Exception
End Try
Else
'do a simple save...
CType(L(0), ImageItem).Image.Save(f, ImageFormat.Tiff)
End If


Please remember that this code was gleaned from various sources (mostly Bob
Powell's excellent tutorials on GDI+!) so I don't claim to understand it all.
Any assistance in getting the new image to be the same orientation and size
as the old image would be GREATLY appreciated...

background
You may wonder why I'm simply reading an image and rewriting it to another
image... Good question. The project I'm working on is to take inbound
Purchase orders that are faxed and convert them to EDI documents for
importing into our order entry system. The images are run through OCR
software to produce a text file that is scanned for various pieces of
information and then written to an XML file for import. Unfortunately, some
of the images that get written from our network fax server contain some sort
of anomoly in the data that keeps it from being read by the OCR package
(Omnipage). Even Photoshop cannot read the images. Windows picture & fax
view will display and print them, though. I stumbled on the thought of
reading & rewriting the image to see if VB could read it. Lo and behold, the
OCR software can read the newly created file!!! Now I'm trying to work with
multipage images and having the above problems. Sorry for the length but I
felt that more background was better than none.
/background


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.