I spent hours working on this code, but I finally have it working somewhat (DDT version).
The code works perfectly for loading JPeg,GIF and PNG images and returning an API Bitmap handle. SDK'ers get perfect working code.
I finally got it working where it can return a DDT Bitmap handle (not the same an API bitmap), but the routine has go through hoops to do it. The image has to be loaded into a 24 bit DIB and then run through the image using pointers inverting all the pixel bytes and then swapping the red and blue pixels. I am not sure, but I think DDT stores images in CMYK format rather than RGB.
The code works, but for some unknown reason when I BitBlt the image to a DDT bitmap, there is a white line at the top.
Maybe someone can figure it out, so even the DDT version works perfectly. But I did the hard stuff.
You can see the code and download it here:
http://cwsof.com/forums/index.php?topic=488.0
The beauty of this include file is that it does not require any GDI+ API includes to use it. All the GDI+ declarations necessary are in it.
At least for SDK coders you can now load JPeg,GIF and PNG effortlessly. Just add the include to your app and then a simple call loads the image, like this:
ie.
hBmp = GDIP_LoadImage(0, F$, -1,-1,1)
Loads image and returns an API Bitmap.
There are two functions in the include, which are:
GDIP_GetImageSize F$, W&, H&
Reads an image file and returns the size (width and height) in pixels, without loading.
F$ is the filename (full path) of any Image file windows supports (ie. JPeg, PNG, GIF)
W& is a long variable to return the width in pixels
H& is a long variable to return the height in pixels
hBmp& = GDIP_LoadImage(DMode&, F$, W&, H&, QFlag&)
Loads an image file (JPeg,GIF or PNG)
DMode& if non-zero (1) makes function return a DDT Bitmap, rather than an API Bitmap
F$ is the filename (full path) of any Image file windows supports (ie. JPeg, PNG, GIF)
W& is the requested width of the image (in pixels)
H& is the requested height of the image (in pixels)
QFlag& if set to non-zero (1) requests best quality possible image
If W& and H& are set to -1 (or even zero) then the routine will use the actual size of the image on file.
The return value is a Bitmap handle.
If DMode& is non-zero (1) then the handle is a DDT Bitmap handle which can only be used with DDT Graphic commands.
If DMode& is zero, then the handle is an API Bitmap handle, which can only be used with the API and not DDT Graphic commands.
The code is based on code by Dan Ginzel, but totally reworked to make it simple and easy to use.
Enjoy!
The code works perfectly for loading JPeg,GIF and PNG images and returning an API Bitmap handle. SDK'ers get perfect working code.
I finally got it working where it can return a DDT Bitmap handle (not the same an API bitmap), but the routine has go through hoops to do it. The image has to be loaded into a 24 bit DIB and then run through the image using pointers inverting all the pixel bytes and then swapping the red and blue pixels. I am not sure, but I think DDT stores images in CMYK format rather than RGB.
The code works, but for some unknown reason when I BitBlt the image to a DDT bitmap, there is a white line at the top.
Maybe someone can figure it out, so even the DDT version works perfectly. But I did the hard stuff.
You can see the code and download it here:
http://cwsof.com/forums/index.php?topic=488.0
The beauty of this include file is that it does not require any GDI+ API includes to use it. All the GDI+ declarations necessary are in it.
At least for SDK coders you can now load JPeg,GIF and PNG effortlessly. Just add the include to your app and then a simple call loads the image, like this:
ie.
hBmp = GDIP_LoadImage(0, F$, -1,-1,1)
Loads image and returns an API Bitmap.
There are two functions in the include, which are:
GDIP_GetImageSize F$, W&, H&
Reads an image file and returns the size (width and height) in pixels, without loading.
F$ is the filename (full path) of any Image file windows supports (ie. JPeg, PNG, GIF)
W& is a long variable to return the width in pixels
H& is a long variable to return the height in pixels
hBmp& = GDIP_LoadImage(DMode&, F$, W&, H&, QFlag&)
Loads an image file (JPeg,GIF or PNG)
DMode& if non-zero (1) makes function return a DDT Bitmap, rather than an API Bitmap
F$ is the filename (full path) of any Image file windows supports (ie. JPeg, PNG, GIF)
W& is the requested width of the image (in pixels)
H& is the requested height of the image (in pixels)
QFlag& if set to non-zero (1) requests best quality possible image
If W& and H& are set to -1 (or even zero) then the routine will use the actual size of the image on file.
The return value is a Bitmap handle.
If DMode& is non-zero (1) then the handle is a DDT Bitmap handle which can only be used with DDT Graphic commands.
If DMode& is zero, then the handle is an API Bitmap handle, which can only be used with the API and not DDT Graphic commands.
The code is based on code by Dan Ginzel, but totally reworked to make it simple and easy to use.
Enjoy!
Comment