Re: TIFF Creation Issues...

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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>
.



Relevant Pages

  • Tiff File Creation For Fax With FAXCOMLib
    ... I have created an array of images and converted them to 1pbb ... The .Tiff file appears to be created successfully however when I try to send ... Dim fs As New FAXCOMLib.FaxServerClass ... Private Function createTiffImage(ByVal bitmapArray() As Bitmap) As String ...
    (microsoft.public.dotnet.languages.vb)
  • Re: TIFF Creation Issues...
    ... multipage tiff. ... the new images are rotated 90 degrees and occupies only ... Dim bm As Bitmap = CType, ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Linked Images missing in PP2007
    ... I can learn anything about links to images with spaces in the name, ... Dim Logger As Integer ... "Steve Rindsberg" wrote: ... Steve Rindsberg, PPT MVP ...
    (microsoft.public.powerpoint)
  • Re: TIFF Creation Issues...
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... the new images are rotated 90 degrees and occupies only ... Dim bm As Bitmap = CType, ...
    (microsoft.public.dotnet.framework.drawing)
  • TIFF Creation Issues...
    ... the new images are rotated 90 degrees and occupies only ... Dim bm As Bitmap = CType, ... You may wonder why I'm simply reading an image and rewriting it to another ...
    (microsoft.public.dotnet.framework.drawing)