我在处理大图像时遇到一个奇怪的问题(大小约为48 mb,一个有175页的Tiff文件)。现在当我试图将Imagefile转换为位图并进行一些操作时,随机系统会抛出“Out of memory exception”
以下是我的代码段。我在“pages = New Bitmap(lorigionalFile)”行上得到错误(随机),其中LoriginalFile是ImageType而Page是Bitmap。
所以请指导我如何删除此类错误或停止内存泄漏。
Dim lorigionalFile As System.Drawing.Image
Dim SaveEncodeParam As EncoderParameter 'Encoder parameter to create multi page image
Dim EncoderParams As EncoderParameters = New EncoderParameters(1) 'Encoder parameter Array
Dim pages As Bitmap 'Used to save image page
Dim NextPage As Bitmap 'Used to save next image page
Dim PageNumber As Integer
Lfr = File.Open(FileName, FileMode.Open, FileAccess.ReadWrite)
lorigionalFile = System.Drawing.Image.FromStream(Lfr)
''Get number of page count in image
PageNumber = getPageNumber(lorigionalFile)
'set first page as active frame
cintPagenumber = PageNumber
'loop to every page of attached document
For i As Integer = 0 To PageNumber - 1
'set active from as per loop variable
lorigionalFile.SelectActiveFrame(FrameDimension.Page, i)
'Will get errow in below line(randomly), when there are other programs running in background
pages = New Bitmap(lorigionalFile)
'image store in Image
CalImageContainer.Add(pages)
'make a copy on image container
CalImageContainerCopy.Add(pages)
Next
Lfr.Close()
End Try
由于
Pratik vohera
答案 0 :(得分:0)