saving a Sprite off screen as a PNG?
Posted: Mon Jun 25, 2007 4:36 am
Ok, I'm finding out I know very little about grabbing images and saving them, using code I found on the forums (thanks guys
), I can grab a sprite and display it in an image gadget, but I cant for the life of me figure out how to save it to a PNG, heres the basics of what I've got...
now I know to to save it has to be an image number Not an ImageID, is there any way around this?
Thanks in advance

Code: Select all
If UsePNGImageDecoder() And UsePNGImageEncoder() And InitSprite()
OpenWindow(1, 0, 0, 1024, 768, "Test",#PB_Window_BorderLess)
OpenWindowedScreen(WindowID(1), 0, 0, 1024, 768,0,0,0)
Procedure CreateBitmapFromSprite(Sprite)
hDC=StartDrawing(SpriteOutput(Sprite))
bmp.BITMAP\bmWidth=SpriteWidth(Sprite)
bmp\bmHeight=SpriteHeight(Sprite)
bmp\bmPlanes=1
bmp\bmBitsPixel=GetDeviceCaps_(hDC,#BITSPIXEL)
bmp\bmBits=DrawingBuffer()
bmp\bmWidthBytes=DrawingBufferPitch()
hBmp=CreateBitmapIndirect_(bmp)
StopDrawing()
ProcedureReturn hbmp
EndProcedure
Procedure SendAnswer()
GrabSprite(50,40,40,709,650)
ImageId=CreateBitmapFromSprite(50)
SaveImage(ImageId, "answer.png", #PB_ImagePlugin_PNG)
FreeSprite(50)
EndProcedure
endif
Thanks in advance
