Page 1 of 1
Copy a 2D Sprite to an Image?
Posted: Sun Jan 30, 2005 3:01 am
by Shannara
Does anybody know the quickest way to copy a 2D sprite (not 3d), to an Image?
Such as something like ..
tmpImage.l
tmpImage = CopyFromSprite(SpriteID)
?
Or some way to get a pointer to a sprite, so then I can use CatchImage?
tmpImage = CatchImage(#PB_ANY, SpritePointer)
Posted: Sat Feb 26, 2005 5:17 am
by waffle
SpareImage=CreateSprite(#PB_Any,TileWidth,TileHeight)
spop=SpriteOutput(SpareImage)
StartDrawing(spop)
DrawImage(UseImage(OKSpot),0,0,TileWidth,TileHeight)
StopDrawing()
OKSpot=SpareImage
....
But this assumes you know the image used to create the sprite ...
It does resize the original image to match the size of the new sprite.
Another option would be to past the sprite to your screen, and then take
a screen shot of that spot .....
Posted: Sat Feb 26, 2005 7:09 pm
by S.M.
@Shannara
This should be a fast way:
Code: Select all
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
;Example:
InitSprite()
OpenScreen(800,600,16,"TEST")
LoadSprite(1,"C:\Programme\PureBasic\Examples\Sources\Data\Background.bmp",#PB_Sprite_Memory)
ImageID=CreateBitmapFromSprite(1)
StartDrawing(ScreenOutput())
DrawImage(ImageID,0,0,800,600)
StopDrawing()
FlipBuffers()
Delay(2000)
DeleteObject_(ImageID);Don't forget to free the bitmap
regards
Stefan
Posted: Sun Feb 27, 2005 6:27 pm
by waffle
wow
thanks, I'll add that code and a thankyou into my grab bag of code...
so, if I was using a sprite to combine various effects, I would then copy it
to memory ...
Result = CopySprite(#Sprite1, #Sprite2 [, Mode])
and then call your function so that the sprite would be
copyied to an image, the image could then be resized and
then used for other sprites or saved ...
cool.
Posted: Mon Feb 28, 2005 9:09 am
by griz
Cool, thanks S.m.
How about moving an image back to a sprite?
Posted: Mon Feb 28, 2005 3:15 pm
by S.M.
@griz
Here, is a procedure which makes a sprite out of a image.
Code: Select all
Procedure CreateSpriteFromBitmap(Sprite,ImageID)
GetObject_(ImageID,SizeOf(BITMAP),bmp.BITMAP)
CreateSprite(Sprite,bmp\bmWidth,bmp\bmHeight)
MemDC=CreateCompatibleDC_(0)
OldBitmap=SelectObject_(MemDC,ImageID)
hDC=StartDrawing(SpriteOutput(Sprite))
BitBlt_(hDC,0,0,bmp\bmWidth,bmp\bmHeight,MemDC,0,0,#SRCCOPY)
SelectObject_(MemDC,OldBitmap)
DeleteDC_(MemDC)
StopDrawing()
EndProcedure
;Example:
InitSprite()
OpenScreen(800,600,16,"CreateSpriteFromBitmap()")
ImageID=LoadImage(1,"C:\Programme\PureBasic\Examples\Sources\Data\Background.bmp")
CreateSpriteFromBitmap(1,ImageID)
DisplaySprite(1,0,0)
FlipBuffers()
Delay(1000)
regards
Stefan
Posted: Tue Mar 01, 2005 1:33 am
by griz
Thanks S.M.

Posted: Fri Mar 25, 2005 7:57 am
by Shannara
S.M.:
Is there a way to do that without using the harddrive, like in pure memory? Right now, due to the
OpenWindowedScreen bug in PBWin 3.93, I have to do a work around and am looking for a way to do so without accessing the harddrive twice.
Right now I use vBin (version 1) to place all my images into a packed file. Then I catch the images into an Image variable (placeholder), this is in the beginning of the program before openwindowedscreen is called. Then, once the open screen is called, Im looking for a way to direct (memory) copy the image onto an empty sprite ..
In PBWIN 3.92, I can openwindowedscreen on an hidden regular window, and it will not show until I unhide the window (normal), and because of that, I was able to catch the sprites directly from the pack files ... in 3.93, I can no longer do that.
[/url]
Posted: Fri Mar 25, 2005 11:32 am
by S.M.
Hi Shannara
Is there a way to do that without using the harddrive, like in pure memory? Right now, due to the OpenWindowedScreen bug in PBWin 3.93, I have to do a work around and am looking for a way to do so without accessing the harddrive twice.
Neither CreateSpriteFromBitmap() nor CreateBitmapFromSprite() use the harddisk.
In PBWIN 3.92, I can openwindowedscreen on an hidden regular window, and it will not show until I unhide the window (normal), and because of that, I was able to catch the sprites directly from the pack files ... in 3.93, I can no longer do that.
You can do it this way, till Fred fix this ugly bug:
Code: Select all
InitSprite()
OpenWindow(1,0,0,640,480,#PB_Window_SystemMenu|#PB_Window_Invisible,"DX")
OpenWindowedScreen(WindowID(),0,0,640,480,0,0,0)
ShowWindow_(WindowID(),#SW_HIDE) ;HideWindow(WindowID(),1) crashes !
Delay(2500)
ShowWindow_(WindowID(),#SW_SHOW)
Repeat
ClearScreen(0,0,128)
FlipBuffers()
Until WindowEvent()=#PB_Event_CloseWindow
The only problem is that the window is shown for a few milliseconds. :roll:
regards
Stefan
Posted: Sat Apr 02, 2005 2:20 am
by Shannara
Thanks for the info

Sorry about taking so long for a reply.