|
|
|
start date: Fri, 17 Aug 2007 14:36:36 -0500,
posted on: microsoft.public.dotnet.framework.drawing
back
| Thread Index |
|
1
SR
|
|
2
SR
|
|
3
Bob Powell [MVP]
|
Combining Single Page TIFFs into 1 multipage TIFF
I have a directory full of single page TIFFs. I would like to write a
program that will combine all of them into 1 multipage TIFF. Here is my
code. I am getting a "Parameter not valid" error message when performing
the SaveAdd methods. Any help would be appreciated!
oFiles = oDir.GetFiles("*.tif")
If oFiles.Length > 0 Then
miFileCnt += 1
sSplit = zsDirectory.Split("\")
sOutTiff = txtOutpath.Text & "\" & sSplit(sSplit.Length - 1)
& "_SDISM_" & miFileCnt.ToString.PadLeft(5, "0") & ".tif"
oBmp = Nothing
For Each oFile As FileInfo In oFiles
laCurrentFile.Text = oFile.Name
Application.DoEvents()
oCurrImage = Image.FromFile(oFile.FullName)
iFrameCnt =
oCurrImage.GetFrameCount(FrameDimension.Page)
If oBmp Is Nothing Then
oBmp = New Bitmap(oCurrImage)
oBmp.Save(sOutTiff, moImageInfo, moParams)
iStart = 1
Else
iStart = 0
End If
oMS = New MemoryStream
moParams.Param(0) = New EncoderParameter(moEncoder,
CLng(EncoderValue.FrameDimensionPage))
For iCnt As Integer = iStart To iFrameCnt - 1
oCurrImage.SelectActiveFrame(FrameDimension.Page,
iCnt)
oCurrImage.Save(oMS, ImageFormat.Bmp)
oNewImage = Image.FromStream(oMS)
oBmp.SaveAdd(oNewImage, moParams)
oMS.SetLength(0)
Next
oCurrImage.Dispose()
oBmp.Dispose()
Next
oMS.Dispose()
oNewImage.Dispose()
End If
TIA,
SR
Date:Fri, 17 Aug 2007 14:36:36 -0500
Author:
|
Re: Combining Single Page TIFFs into 1 multipage TIFF
I figured it out...
oFiles = oDir.GetFiles("*.tif")
If oFiles.Length > 0 Then
miFileCnt += 1
sSplit = zsDirectory.Split("\")
sOutTiff = txtOutpath.Text & "\" & sSplit(sSplit.Length - 2) & "_SDISM_" &
miFileCnt.ToString.PadLeft(5, "0") & ".tif"
oNewImage = Nothing
For Each oFile As FileInfo In oFiles
laCurrentFile.Text = oFile.Name
Application.DoEvents()
If oNewImage Is Nothing Then
oNewImage = Image.FromFile(oFile.FullName)
oNewImage.Save(sOutTiff, moImageInfo, encParamsMulti)
iStart = 1
Else
oCurrImage = Image.FromFile(oFile.FullName)
oNewImage.SaveAdd(oCurrImage, encParamsAdd)
iStart = 0
End If
If oCurrImage IsNot Nothing Then
oCurrImage.Dispose()
End If
Next
oNewImage.SaveAdd(encParamsFlush)
oNewImage.Dispose()
End If
"SR" wrote in message
news:uRF5VYQ4HHA.5724@TK2MSFTNGP05.phx.gbl...
>I have a directory full of single page TIFFs. I would like to write a
>program that will combine all of them into 1 multipage TIFF. Here is my
>code. I am getting a "Parameter not valid" error message when performing
>the SaveAdd methods. Any help would be appreciated!
>
> oFiles = oDir.GetFiles("*.tif")
> If oFiles.Length > 0 Then
> miFileCnt += 1
> sSplit = zsDirectory.Split("\")
> sOutTiff = txtOutpath.Text & "\" & sSplit(sSplit.Length -
> 1) & "_SDISM_" & miFileCnt.ToString.PadLeft(5, "0") & ".tif"
> oBmp = Nothing
>
> For Each oFile As FileInfo In oFiles
> laCurrentFile.Text = oFile.Name
> Application.DoEvents()
>
> oCurrImage = Image.FromFile(oFile.FullName)
> iFrameCnt =
> oCurrImage.GetFrameCount(FrameDimension.Page)
>
> If oBmp Is Nothing Then
> oBmp = New Bitmap(oCurrImage)
> oBmp.Save(sOutTiff, moImageInfo, moParams)
>
> iStart = 1
> Else
> iStart = 0
> End If
>
> oMS = New MemoryStream
>
> moParams.Param(0) = New EncoderParameter(moEncoder,
> CLng(EncoderValue.FrameDimensionPage))
> For iCnt As Integer = iStart To iFrameCnt - 1
> oCurrImage.SelectActiveFrame(FrameDimension.Page,
> iCnt)
> oCurrImage.Save(oMS, ImageFormat.Bmp)
>
> oNewImage = Image.FromStream(oMS)
>
> oBmp.SaveAdd(oNewImage, moParams)
>
> oMS.SetLength(0)
> Next
>
> oCurrImage.Dispose()
> oBmp.Dispose()
> Next
>
> oMS.Dispose()
> oNewImage.Dispose()
> End If
>
> TIA,
> SR
>
Date:Fri, 17 Aug 2007 16:24:48 -0500
Author:
|
Re: Combining Single Page TIFFs into 1 multipage TIFF
You may also want to see the examples 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.
"SR" wrote in message
news:uRF5VYQ4HHA.5724@TK2MSFTNGP05.phx.gbl...
>I have a directory full of single page TIFFs. I would like to write a
>program that will combine all of them into 1 multipage TIFF. Here is my
>code. I am getting a "Parameter not valid" error message when performing
>the SaveAdd methods. Any help would be appreciated!
>
> oFiles = oDir.GetFiles("*.tif")
> If oFiles.Length > 0 Then
> miFileCnt += 1
> sSplit = zsDirectory.Split("\")
> sOutTiff = txtOutpath.Text & "\" & sSplit(sSplit.Length -
> 1) & "_SDISM_" & miFileCnt.ToString.PadLeft(5, "0") & ".tif"
> oBmp = Nothing
>
> For Each oFile As FileInfo In oFiles
> laCurrentFile.Text = oFile.Name
> Application.DoEvents()
>
> oCurrImage = Image.FromFile(oFile.FullName)
> iFrameCnt =
> oCurrImage.GetFrameCount(FrameDimension.Page)
>
> If oBmp Is Nothing Then
> oBmp = New Bitmap(oCurrImage)
> oBmp.Save(sOutTiff, moImageInfo, moParams)
>
> iStart = 1
> Else
> iStart = 0
> End If
>
> oMS = New MemoryStream
>
> moParams.Param(0) = New EncoderParameter(moEncoder,
> CLng(EncoderValue.FrameDimensionPage))
> For iCnt As Integer = iStart To iFrameCnt - 1
> oCurrImage.SelectActiveFrame(FrameDimension.Page,
> iCnt)
> oCurrImage.Save(oMS, ImageFormat.Bmp)
>
> oNewImage = Image.FromStream(oMS)
>
> oBmp.SaveAdd(oNewImage, moParams)
>
> oMS.SetLength(0)
> Next
>
> oCurrImage.Dispose()
> oBmp.Dispose()
> Next
>
> oMS.Dispose()
> oNewImage.Dispose()
> End If
>
> TIA,
> SR
>
Date:Sat, 18 Aug 2007 13:43:32 +0200
Author:
|
|
|