Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OutOfMemory loading image in DataGridViewImageColumn

Status
Not open for further replies.

ProtocolPirate

Programmer
Nov 21, 2007
104
US

In the CellFormating method of the dgv I have the following code:

Private Sub DataGridView_Images_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView_Images.CellFormatting
If e.ColumnIndex = 0 Then
e.Value = Image.FromFile("Y:\BRE0080236\AI.pdf")
End If
End Sub

There is only one row in the grid, and the code is bombing on the first call to CellFormating. Eventually I will have the image for each row loaded from a string field in the row.

I've seen this example over and over on the web, does anyone have any idea what I am doing wrong?
 
I don't know if this is the case that you are running into, but I've had many issues with pdf files and memory issues. I would recommend trying to (if you have adobe professional) reduce the file size by going to File ... Reduce File Size ... and save to a later version. You could also save it optimized for the web to reduce file size. This is what I would try before modifying the code.
 
I tried with a 170K jpg and got the same results, but then with a 20K jpg and it worked. Those are some TIGHT restrictions on what size will be accepted...
 
I'm talking with very little experience with this, but I'll speak and maybe something I say will help.

1) If the PDF is a multiple page document it is generally going to have a problem.

2) From the help: OutOfMemoryException will be thrown if the file does not have a valid image format or (didn't know this part) the GDI+ does not support the pixel format of the file.

I don't know what about multiple page PDF's cause the problem, but they can. It could just be the multiple pages themselves or how the PDF was saved. I was making a picture viewer (I still work on if off/on) and sometimes it would show a mini picture of the PDF and other times cause an error. I never found out for sure what cause the problem (since I really didn't want it to view the PDF any way) so I just skipped it. The thing is the ones it had a problem with all had multiple pages. It could have been the page count (anywhere from 10 to 75) or something else.

-I hate Microsoft!
-Forever and always forward.
 
My PDFs are only one page and the problem happens with JPGs of the same size as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top