Copy image from LoadImage_() into PB-image

Just starting out? Need help? Post your questions and find answers here.
User avatar
Jac de Lad
Enthusiast
Enthusiast
Posts: 106
Joined: Wed Jul 15, 2020 7:10 am
Contact:

Copy image from LoadImage_() into PB-image

Post by Jac de Lad »

Hi,
I didn't find a solution via Google and forum search: I have an image loaded via LoadImage_()-API and want to pass it to a PureBasic written DLL. How can I grab the image and put it into a PureBasic image?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Copy image from LoadImage_() into PB-image

Post by RASHAD »

Hi

Code: Select all

OpenWindow(0,0,0,400,400,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
imgH = LoadImage_(0,"g:\mmedia\pictures\girl8.bmp",#IMAGE_BITMAP,128,128,#LR_LOADFROMFILE)
PBimg = CreateImage(#PB_Any,128,128,32)
StartDrawing(ImageOutput(PBimg))
  DrawImage(imgH,0,0)
StopDrawing()
DeleteObject_(imgH)
ImageGadget(0,0,0,400,400,ImageID(PBimg))
;FreeImage(PBimg)
Repeat
  Select WaitWindowEvent()
      
       Case #PB_Event_CloseWindow
            Quit = 1
            
  EndSelect 

Until Quit = 1
End
Egypt my love
User avatar
Jac de Lad
Enthusiast
Enthusiast
Posts: 106
Joined: Wed Jul 15, 2020 7:10 am
Contact:

Re: Copy image from LoadImage_() into PB-image

Post by Jac de Lad »

Hi rashad,
yes of course. I just realized that I've done this before...anyway, thanks for the answer.
How do I get the dimensions of the picture (which I don't know beforehand)? I guess I need

Code: Select all

Define dimensions.bitmap
GetObject_(myimage, sizeof(dimensions),dimensions)
Debug "width: "+Str(dimensions\bmwidth)
Debug "height: "+Str(dimensions\bmheight)
?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Copy image from LoadImage_() into PB-image

Post by RASHAD »

With LoadImage_() you already know the image width & height

Code: Select all

HANDLE LoadImage(

    HINSTANCE  hinst, 	// handle of the instance that contains the image
    LPCTSTR  lpszName,	// name or identifier of image
    UINT  uType,	// type of image
    int  cxDesired,	// desired width
    int  cyDesired,	// desired height
    UINT  fuLoad	// load flags
   );
Egypt my love
User avatar
Jac de Lad
Enthusiast
Enthusiast
Posts: 106
Joined: Wed Jul 15, 2020 7:10 am
Contact:

Re: Copy image from LoadImage_() into PB-image

Post by Jac de Lad »

Nope, I get the handle passed from an application to my DLL. I know I could also pass the dimensions, but that's not an option, the function is multipurpose and an extra parameter would be useless for all other calls.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Copy image from LoadImage_() into PB-image

Post by RASHAD »

Right answer :)
That explain every thing
Egypt my love
Post Reply