Question How to load image from file using Win32 CreateFile.

miwtech

Member
Joined
Oct 17, 2008
Messages
5
Programming Experience
3-5
I'm want to use Win32 CreateFile to create a GDI+ bitmap. I have the CreateFile function working in VB.Net 2003 but I can't figure out how to create a bitmap from the file handle.

Can anyone point me in the right direction?

I realize there are easier methods to obtain a bitmap from a file but I need to use CreateFile to bypass the Windows limit of 512 files that can be open at a time.
 
Last edited:
Do you absolutely need to keep all those file handles open? Can't you read the file contents into Image and close each file as you go? Post 2 in this thread has an example: http://www.vbdotnetforums.com/graphics-gdi/21341-how-do-i-remove-reference-file-gdi-exception.html

Do I have to? No.
Do I want to? Yes
Because of the way I'm processing and displaying the imagery, loading to/from disk for every operation I perform is too slow. I want all images to be in memory for instant access.

I had a look at your code segment, and I confess I'm not sure if my understanding of GDI+ is correct, or if the code segment is in error.

This may get complicated but I will try to be clear.

I assume picLogo is a picture box on the form. Program flow is as follows:
Create a dialog.
Load an image to a bitmap from disk.
Create a graphics object.
Process the bitmap, display result in picLogo and save result to disk.

Ok so far but what follows is confusing. The dialog is disposed, something I have never seen in any MS docs. And the graphics object is not disposed. In the MS docs graphics objects are always disposed, otherwise they remain persistent. The bitmap looses scope once the routine is finished.

I'm not sure if this is a code error, or if your saying this resolves my issue.

My project runs much nicer with all images in memory. I thought that in order to keep all my images in memory the file references need to remain open. So I wonder if what your saying is I can accomplish this by creating a unique graphics object for each image, and disposing of the dialog will close the file references while keeping the images in memory. If so I would have another question or two. If not then we are not talking about the same thing.

On another matter, I will research the FAQ ect about learning to post properly on this forum, but right at the moment I'm pressed for time.

Thank you for your help.
 
Last edited:
I think you should use the suggested method to load the image file to memory. Always call the Dispose method when you're done using objects. Your other issues sound confusing and not clear to me.
 
Back
Top