I'm trying to insert a page and then apply some text to each page of a multi-page tiff.
If I just want to insert a page without applying any additional text to each page, this code has been working fine:
This is the code I'm using to insert the cover and add additional text to each page:
With larger images, I get "A generic error occurred in GDI+." "[ExternalException (0x80004005): A generic error occurred in GDI+.]" at bitmap2.Save(byteStream, ImageFormat.Tiff) once I hit about the 20th image. Any thoughts as to what the issue is and how I might resolve it?
If I just want to insert a page without applying any additional text to each page, this code has been working fine:
VB.NET:
'some stuff to insert the cover
'loop through each page of the multi-page tif
Dim byteStream As New MemoryStream()
Dim count As Integer = bitmap.GetFrameCount(FrameDimension.Page)
For idx As Integer = 0 To count - 1
bitmap.SelectActiveFrame(FrameDimension.Page, idx)
bitmap.Save(byteStream, ImageFormat.Tiff)
images.Add(Image.FromStream(byteStream))
Next
'some stuff to process and save a tif
This is the code I'm using to insert the cover and add additional text to each page:
VB.NET:
'some stuff to insert the cover
'loop through each page of the multi-page tif
Dim byteStream As New MemoryStream()
Dim count As Integer = bitmap.GetFrameCount(FrameDimension.Page)
For idx As Integer = 0 To count - 1
bitmap.SelectActiveFrame(FrameDimension.Page, idx)
Dim bitmap2 As New Bitmap(bitmap)
bitmap2.SetResolution(300, 300)
Dim g As Graphics = Graphics.FromImage(bitmap2)
Select Case Trim(Type)
Case Is = "X"
Dim rectf As New RectangleF(2100, 75, 300, 75)
g.DrawString(DocNum, New Font("Arial", 10), Brushes.Black, rectf, stringFormat)
Case Is = "Y"
Dim rectf As New RectangleF(2100, 150, 300, 75)
g.DrawString(DocNum, New Font("Arial", 10), Brushes.Black, rectf, stringFormat)
End Select
bitmap2.Save(byteStream, ImageFormat.Tiff)
images.Add(Image.FromStream(byteStream))
g.Dispose()
bitmap2.Dispose()
Next
'some stuff to process and save a tif
With larger images, I get "A generic error occurred in GDI+." "[ExternalException (0x80004005): A generic error occurred in GDI+.]" at bitmap2.Save(byteStream, ImageFormat.Tiff) once I hit about the 20th image. Any thoughts as to what the issue is and how I might resolve it?
Last edited: