Copy a 2D Sprite to an Image?
Copy a 2D Sprite to an Image?
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)
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)
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 .....
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 .....
@Shannara
This should be a fast way:
regards
Stefan
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
Stefan
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.
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.
Code is good... Its an international language.
@griz
Here, is a procedure which makes a sprite out of a image.
regards
Stefan
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)
Stefan
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]
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]
Hi Shannara
The only problem is that the window is shown for a few milliseconds. :roll:
regards
Stefan
Neither CreateSpriteFromBitmap() nor CreateBitmapFromSprite() use the harddisk.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.

You can do it this way, till Fred fix this ugly bug: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.
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
regards
Stefan