我已经阅读了数百个" GDI +中出现了一般性错误"帖子并不能完全解决问题。我试图插入一个页面,然后将一些文本应用到多页tiff的每个页面。
如果我只是想在不向每个页面添加任何其他文本的情况下插入页面,则无论多页tiff包含多少页面,此代码都能正常工作:
'yada yada yada
cover.Save(byteStream, ImageFormat.Tiff)
images.Add(Image.FromStream(byteStream))
'loop through each page of the multi-page tif
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
这是我用来插入封面并为每个页面添加其他文字的代码。它似乎工作正常,除非多页tiff有超过20页:
'yada yada yada
cover.Save(byteStream, ImageFormat.Tiff)
images.Add(Image.FromStream(byteStream))
Dim stringFormat As StringFormat = New StringFormat()
stringFormat.Alignment = StringAlignment.Far
'loop through each page of the multi-page tif
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
我得到" GDI +中发生了一般错误。" " [ExternalException(0x80004005):GDI +中发生了一般错误。]" at bitmap2.Save(byteStream,ImageFormat.Tiff)一旦我点击第20张图片。关于问题是什么以及如何解决它的任何想法?它似乎不是文件权限问题。我尝试使用"使用"使用内存流结束"而且似乎并不重要。我错过了一些明显的东西吗