• Welcome to Theos PowerBasic Museum 2017.

Problems With GdipCreateHBITMAPFromBitmap

Started by Anthony Watson, August 22, 2009, 06:22:46 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Anthony Watson

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

Patrice Terrier

#1
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 Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Anthony Watson

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

Patrice Terrier

How large are the pictures: Width Height in pixel
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Edwin Knoppert


Patrice Terrier

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.
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Anthony Watson

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

José Roca

Try this:


hr2=GdipCreateHBITMAPFromBitmap(pBitmap,hBitmap,0)
IF hr2 = 7 THEN hr = GetLastError


GetLastError should return the Windows error code.

Jürgen Huhn

I have a short Question!

The number Hr2 = 7 is the Definition " %OBJ_BITMAP "... Is that right??
.¸.•'´¯)¸.•'´¯)¸.•'´¯)¸.•'´¯)
¤ª"˜¨¨¯¯¨¨˜"ª¤....¤ ª"˜¨

José Roca

 
No. It is the Win32Error member of the Status enumeration. It means that a Windows error has happened.

Jürgen Huhn

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.


...
.¸.•'´¯)¸.•'´¯)¸.•'´¯)¸.•'´¯)
¤ª"˜¨¨¯¯¨¨˜"ª¤....¤ ª"˜¨