HighTechTalks DotNet Forums  

Resize Multipage TIFF

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


Discuss Resize Multipage TIFF in the Dotnet Framework (Drawing) forum.



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

Default Resize Multipage TIFF - 03-29-2007 , 06:57 PM






Hi All,

I'm am having trouble resizing a multipage TIFF file. The TIFF is 640x480
and I am trying to resize ALL frames to 320x280. If I resize it by creating
a new bitmap at the target size and resave, it loses the pages. If I loop
through all the pages and resize each page into new bitmap, then recreate
the TIFF, I get an Invalid Parameter Used exception. What is confusing is
that the code to create a multipaged TIFF from an array of newly drawn
images works. It seems to be when I open a multipaged TIFF and try to use
copies of the frames as a source for another TIFF where the issue occurs.

Dim imageFile As System.IO.StreamReader = New
System.IO.StreamReader("my_multipaged_tiff.tiff")
Dim tiffImage As System.Drawing.Bitmap = New Bitmap(imageFile.BaseStream)
Dim images(tiffImage.GetFrameCount(Imaging.FrameDimens ion.Page) - 1) As
Drawing.Bitmap

For imageIndex As Int32 = 0 To images.GetUpperBound(0)
tiffImage.SelectActiveFrame(Drawing.Imaging.FrameD imension.Page,
imageIndex)
images(imageindex) = GetReducedImage(CType(tiffImage.Clone, Bitmap))
Next



FYI

Public Shared Function GetReducedImage(ByRef image As Bitmap) As Bitmap

Dim result As Image = New Bitmap(image.Width,
image.Height,Imaging.PixelFormat.Format16bppRgb555 )
g = Graphics.FromImage(result)
g.DrawImageUnscaled(image, 0, 0)

Return CType(result, Bitmap)

End Function



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

Default Re: Resize Multipage TIFF - 03-30-2007 , 07:53 AM






Check out the multi-page TIFF articles in the GDI+ FAQ.
--
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.





landers wrote:
Quote:
Hi All,

I'm am having trouble resizing a multipage TIFF file. The TIFF is 640x480
and I am trying to resize ALL frames to 320x280. If I resize it by creating
a new bitmap at the target size and resave, it loses the pages. If I loop
through all the pages and resize each page into new bitmap, then recreate
the TIFF, I get an Invalid Parameter Used exception. What is confusing is
that the code to create a multipaged TIFF from an array of newly drawn
images works. It seems to be when I open a multipaged TIFF and try to use
copies of the frames as a source for another TIFF where the issue occurs.

Dim imageFile As System.IO.StreamReader = New
System.IO.StreamReader("my_multipaged_tiff.tiff")
Dim tiffImage As System.Drawing.Bitmap = New Bitmap(imageFile.BaseStream)
Dim images(tiffImage.GetFrameCount(Imaging.FrameDimens ion.Page) - 1) As
Drawing.Bitmap

For imageIndex As Int32 = 0 To images.GetUpperBound(0)
tiffImage.SelectActiveFrame(Drawing.Imaging.FrameD imension.Page,
imageIndex)
images(imageindex) = GetReducedImage(CType(tiffImage.Clone, Bitmap))
Next



FYI

Public Shared Function GetReducedImage(ByRef image As Bitmap) As Bitmap

Dim result As Image = New Bitmap(image.Width,
image.Height,Imaging.PixelFormat.Format16bppRgb555 )
g = Graphics.FromImage(result)
g.DrawImageUnscaled(image, 0, 0)

Return CType(result, Bitmap)

End Function



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

Default Re: Resize Multipage TIFF - 04-01-2007 , 05:58 PM



Hi Bob,

Already checked the website out and it doesn't really answer my question.

I am trying to read a multipaged TIFF in, resize it and write it out to a
new TIFF. I can already get random images and create a multipaged TIFF, but
its when my source images are from a page within a TIFF where I get the
problem.

Landers.

"Bob Powell [MVP]" <bob (AT) _spamkiller_bobpowell (DOT) net> wrote

Quote:
Check out the multi-page TIFF articles in the GDI+ FAQ.
--
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.





landers wrote:
Hi All,

I'm am having trouble resizing a multipage TIFF file. The TIFF is
640x480 and I am trying to resize ALL frames to 320x280. If I resize it
by creating a new bitmap at the target size and resave, it loses the
pages. If I loop through all the pages and resize each page into new
bitmap, then recreate the TIFF, I get an Invalid Parameter Used
exception. What is confusing is that the code to create a multipaged
TIFF from an array of newly drawn images works. It seems to be when I
open a multipaged TIFF and try to use copies of the frames as a source
for another TIFF where the issue occurs.

Dim imageFile As System.IO.StreamReader = New
System.IO.StreamReader("my_multipaged_tiff.tiff")
Dim tiffImage As System.Drawing.Bitmap = New Bitmap(imageFile.BaseStream)
Dim images(tiffImage.GetFrameCount(Imaging.FrameDimens ion.Page) - 1) As
Drawing.Bitmap

For imageIndex As Int32 = 0 To images.GetUpperBound(0)
tiffImage.SelectActiveFrame(Drawing.Imaging.FrameD imension.Page,
imageIndex)
images(imageindex) = GetReducedImage(CType(tiffImage.Clone, Bitmap))
Next



FYI

Public Shared Function GetReducedImage(ByRef image As Bitmap) As Bitmap

Dim result As Image = New Bitmap(image.Width,
image.Height,Imaging.PixelFormat.Format16bppRgb555 )
g = Graphics.FromImage(result)
g.DrawImageUnscaled(image, 0, 0)

Return CType(result, Bitmap)

End Function



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

Default Re: Resize Multipage TIFF - 04-03-2007 , 06:02 PM



My article explains how to totally decompose a multi page tiff and
insert a new image into it. The implication of this is that you can pull
the thing apart and add back a changed version -ie resized- of the image.

http://www.bobpowell.net/addframes.htm

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





landers wrote:
Quote:
Hi Bob,

Already checked the website out and it doesn't really answer my question.

I am trying to read a multipaged TIFF in, resize it and write it out to a
new TIFF. I can already get random images and create a multipaged TIFF, but
its when my source images are from a page within a TIFF where I get the
problem.

Landers.

"Bob Powell [MVP]" <bob (AT) _spamkiller_bobpowell (DOT) net> wrote in message
news:%23Izb5HscHHA.4984 (AT) TK2MSFTNGP05 (DOT) phx.gbl...
Check out the multi-page TIFF articles in the GDI+ FAQ.
--
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.





landers wrote:
Hi All,

I'm am having trouble resizing a multipage TIFF file. The TIFF is
640x480 and I am trying to resize ALL frames to 320x280. If I resize it
by creating a new bitmap at the target size and resave, it loses the
pages. If I loop through all the pages and resize each page into new
bitmap, then recreate the TIFF, I get an Invalid Parameter Used
exception. What is confusing is that the code to create a multipaged
TIFF from an array of newly drawn images works. It seems to be when I
open a multipaged TIFF and try to use copies of the frames as a source
for another TIFF where the issue occurs.

Dim imageFile As System.IO.StreamReader = New
System.IO.StreamReader("my_multipaged_tiff.tiff")
Dim tiffImage As System.Drawing.Bitmap = New Bitmap(imageFile.BaseStream)
Dim images(tiffImage.GetFrameCount(Imaging.FrameDimens ion.Page) - 1) As
Drawing.Bitmap

For imageIndex As Int32 = 0 To images.GetUpperBound(0)
tiffImage.SelectActiveFrame(Drawing.Imaging.FrameD imension.Page,
imageIndex)
images(imageindex) = GetReducedImage(CType(tiffImage.Clone, Bitmap))
Next



FYI

Public Shared Function GetReducedImage(ByRef image As Bitmap) As Bitmap

Dim result As Image = New Bitmap(image.Width,
image.Height,Imaging.PixelFormat.Format16bppRgb555 )
g = Graphics.FromImage(result)
g.DrawImageUnscaled(image, 0, 0)

Return CType(result, Bitmap)

End Function



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.