I am using GDI+ to load a JPG image and convert it to a bitmap handle I can use in my program. It works perfectly on every computer I have tried it with, but one of my users is receiving an error. Here is a stripped down copy of the code I am using:
LOCAL bm AS BITMAP
LOCAL hr AS LONG
LOCAL strFileName AS STRING
LOCAL pBitmap AS DWORD
LOCAL hBitmap AS DWORD
LOCAL token AS DWORD
LOCAL nStatus AS LONG
LOCAL StartupInput AS GdiplusStartupInput
LOCAL nRect AS RECTL
LOCAL bmpData
itmapData
LOCAL origwidth AS SINGLE
LOCAL origheight AS SINGLE
'** Start GDI+ - Returns 0: Success
StartupInput.GdiplusVersion = 1
nStatus = GdiplusStartup(token, StartupInput, BYVAL 0)
'** Load the JPG image file - Returns 0: Success
strFilename = UCODE$(f$)
hr = GdipCreateBitmapFromFile (strFileName, pBitmap)
'** Obtain image dimensions - Returns proper dimensions
l=GdipGetImageDimension (BYVAL pBitmap, BYREF origwidth, BYREF origheight)
'** Get a bitmap handle for the object - Returns error 7: Win32Error
'** Works fine on every machine I have, but customer machine returns error
hr2=GdipCreateHBITMAPFromBitmap(pBitmap,hBitmap,0)
Any ideas why she is getting Error 7 for the GdipCreateHBITMAPFromBitmap call? I think she is using Windows Vista Ultimate, but am waiting for her to confirm.
Thanks,
Anthony
what are the values returned by orighWidth and origHeight?
Do you dispose the image handle once done, this is not shown in your code?
Also you shoud check the error code returned by the API.
...
Patrice,
The origWidth and origHeight values are both the exact size of the image. The actual values depend on which photo is loaded, but the results are accurate with no errors.
Yes, I call GdipDisposeImage(pBitmap), and delete the bitmap handles at the end of my subroutine, but only posted the code up to the point of the error. I also call GdiplusShutdown at the end of the subroutine.
The only error I receive is the return value from the GdipCreateHBITMAPFromBitmap call, which is the error 7 "Win32Error". Not real helpful in determining what the cause is.
I really don't have a clue what is causing the error.
Thanks,
Anthony
How large are the pictures: Width Height in pixel
(+ colordepth)
The maximum size for a compatible bitmap is 16 Mb.
If larger, then either stretcht it down, or switch to DIB, or keep working with the GDIPLUS image.
mojito.jpg is 33K, 300x300 pixels, 24 bit color depth.
mojito2.jpg is 22K, 300x300 pixels, 24 bit color depth.
GreekDinnerSalad.jpg is 14K, 300x300 pixels, 24 bit color depth.
Forgot to mention, the last test version I sent her the GDI+ calls created a zero byte BMP file for each JPG she tried to load?
Anthony
Try this:
hr2=GdipCreateHBITMAPFromBitmap(pBitmap,hBitmap,0)
IF hr2 = 7 THEN hr = GetLastError
GetLastError should return the Windows error code.
I have a short Question!
The number Hr2 = 7 is the Definition " %OBJ_BITMAP "... Is that right??
No. It is the Win32Error member of the Status enumeration. It means that a Windows error has happened.
I think the Graphics Device Interface (GDI) is different under Windows Vista Ultimate at the DIB-Engine (Device-Independent Bitmap) the GDI-Subsystem!
GDI use the Video-GraphicCard to render Graphic-Data under Windows Vista. Like OpenGL or DirectX!!
That`s new!
Maybe need the use of a Device-Context to create the HBitmap.
...