Theos PowerBasic Museum 2017

Archive => Archived Posts => Topic started by: Anthony Watson on August 22, 2009, 06:22:46 PM

Title: Problems With GdipCreateHBITMAPFromBitmap
Post by: Anthony Watson on August 22, 2009, 06:22:46 PM
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
Title: Re: Problems With GdipCreateHBITMAPFromBitmap
Post by: Patrice Terrier on August 22, 2009, 07:44:23 PM
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.

...
Title: Re: Problems With GdipCreateHBITMAPFromBitmap
Post by: Anthony Watson on August 23, 2009, 05:21:46 PM
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
Title: Re: Problems With GdipCreateHBITMAPFromBitmap
Post by: Patrice Terrier on August 23, 2009, 09:46:01 PM
How large are the pictures: Width Height in pixel
Title: Re: Problems With GdipCreateHBITMAPFromBitmap
Post by: Edwin Knoppert on August 23, 2009, 09:57:09 PM
(+ colordepth)
Title: Re: Problems With GdipCreateHBITMAPFromBitmap
Post by: Patrice Terrier on August 23, 2009, 10:11:30 PM
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.
Title: Re: Problems With GdipCreateHBITMAPFromBitmap
Post by: Anthony Watson on August 24, 2009, 03:24:31 PM
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
Title: Re: Problems With GdipCreateHBITMAPFromBitmap
Post by: José Roca on August 25, 2009, 02:59:43 AM
Try this:


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


GetLastError should return the Windows error code.
Title: Re: Problems With GdipCreateHBITMAPFromBitmap
Post by: Jürgen Huhn on August 31, 2009, 01:44:36 AM
I have a short Question!

The number Hr2 = 7 is the Definition " %OBJ_BITMAP "... Is that right??
Title: Re: Problems With GdipCreateHBITMAPFromBitmap
Post by: José Roca on August 31, 2009, 02:08:09 AM
 
No. It is the Win32Error member of the Status enumeration. It means that a Windows error has happened.
Title: Re: Problems With GdipCreateHBITMAPFromBitmap
Post by: Jürgen Huhn on August 31, 2009, 04:25:16 AM
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.


...