Seite 1 von 2
sprite2image
Verfasst: 23.03.2008 15:18
von Riacon
ich kann aus einem image ein sprite machen:
Code: Alles auswählen
If IsSprite(0)
StartDrawing(SpriteOutput(0))
DrawImage(ImageID(1),0,0)
StopDrawing()
EndIf
geht das auch umgekehrt? aus einem sprite ein image machen?
Verfasst: 23.03.2008 18:02
von AND51
Jo, ist doch ganz einfach
StartDrawing(ImageOutput(0)) ist das Zauberwort:
Code: Alles auswählen
If IsImage(0)
StartDrawing(ImageOutput(0))
DisplaySprite(SprtieID(1),0,0)
StopDrawing()
EndIf
Habe ich aus dem Kopf heraus geschrieben, musst mal testen.
ich nehme an, du verwendest PB 3.94?
Verfasst: 23.03.2008 18:05
von Kaeru Gaman
ne, sprites kannste nit drawen...
Verfasst: 23.03.2008 18:30
von scholly
Die Kette GrabSprite() - SaveSprite() - LoadImage() ist keine Option?
Verfasst: 23.03.2008 18:41
von Riacon
scholly hat geschrieben:Die Kette GrabSprite() - SaveSprite() - LoadImage() ist keine Option?
dauert zu lange. und ist "häßlich"
helfen würde, wenn ich die adresse eines (geladenen) bildes rauskriegen könnte. so in der art:
adr=@image(1)
Verfasst: 23.03.2008 19:11
von scholly
Verfasst: 23.03.2008 19:49
von Riacon
@scholly
sieht gut aus.
abendessen und dann mal ausprobieren
Verfasst: 23.03.2008 21:29
von hjbremer
das Thema hatten wir hier schon mal so ähnlich
http://www.purebasic.fr/german/viewtopi ... sc&start=0
ganz am Ende auf der 2.Seite sind Beispiele
Verfasst: 24.03.2008 19:10
von Riacon
Code: Alles auswählen
;Riacon Bremen, 24.3.08 mit pb 4.1 und xp sp2
;thx to hjbremer+scholly für die tips
;und unbekannterweise an den coder der procedure CreateBitmapFromSprite(Sprite)
;und natürlich an purebasic fred & co und windowbilly
;irgendwo ist hier aber noch ein wurm drin. ich tippe mal auf einen speicherüberlauf, wegen dem häufigen erstellen der bmp's
InitSprite()
Structure pixel
pixel.l
EndStructure
Structure live
farbe.l
x.l
y.l
EndStructure
Global bmp.BITMAP
Global img=0
Global breite=100
Global hoehe=100
Global anzahl=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()
FlipBuffers()
ProcedureReturn hBmp
EndProcedure
Procedure updatehabitat(breite,hoehe,rechenzeit)
Protected qxpos,qypos,txpos,typos,richtung,pitch,*buffer,*qline.pixel,*tline.pixel,*pixel.pixel,beginn,dauer
beginn=ElapsedMilliseconds()
StartDrawing(SpriteOutput(1))
*buffer=DrawingBuffer()
pitch=DrawingBufferPitch()
dauer=0
While rechenzeit>dauer
qxpos=Random(breite-1)
qypos=Random(hoehe-1)
*qline=*buffer+qypos*pitch+qxpos<<2
If *qline\pixel
richtung=Random(7)
Select richtung
Case 0
txpos=qxpos-1
typos=qypos
Case 1
txpos=qxpos+1
typos=qypos
Case 2
txpos=qxpos
typos=qypos-1
Case 3
txpos=qxpos
typos=qypos+1
Case 4
txpos=qxpos-1
typos=qypos-1
Case 5
txpos=qxpos+1
typos=qypos+1
Case 6
txpos=qxpos-1
typos=qypos+1
Case 7
txpos=qxpos+1
typos=qypos-1
EndSelect
If Not(txpos<0 Or typos<0 Or txpos>breite-1 Or typos>hoehe-1)
*tline=*buffer+typos*pitch+txpos<<2
*tline\pixel=*qline\pixel
EndIf
EndIf
dauer=ElapsedMilliseconds()-beginn
Wend
StopDrawing()
EndProcedure
Procedure inithabitat(breite,hoehe,anzahl)
Protected i,xpos,ypos,pitch,*buffer,*line.pixel
If IsSprite(1)
FreeSprite(1)
EndIf
ClearScreen(0)
CreateSprite(1,breite,hoehe)
StartDrawing(SpriteOutput(1))
*buffer=DrawingBuffer()
pitch=DrawingBufferPitch()
For i=1 To anzahl
xpos=Random(breite-1)
ypos=Random(hoehe-1)
farbe=Random(255*255*255)
*line=*buffer+ypos*pitch+xpos<<2
*line\pixel=farbe
Next i
StopDrawing()
img=CreateBitmapFromSprite(1)
EndProcedure
OpenWindow(1, 0, 0, 3*breite, 3*hoehe, "sprite2button",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(1),breite,hoehe,breite,hoehe,0,0,0)
inithabitat(breite,hoehe,anzahl)
CreateGadgetList(WindowID(1))
ButtonImageGadget(1,breite,hoehe,breite,hoehe,img)
GadgetToolTip(1,"DON'T push THIS button")
Repeat
event=WaitWindowEvent(1)
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 1
anzahl+1
inithabitat(breite,hoehe,anzahl)
EndSelect
Default
Delay(1)
EndSelect
updatehabitat(breite,hoehe,5)
SetGadgetState(1,CreateBitmapFromSprite(1))
Until event=#PB_Event_CloseWindow
End
Verfasst: 24.03.2008 20:03
von scholly
Riacon hat geschrieben:;irgendwo ist hier aber noch ein wurm drin. ich tippe mal auf einen speicherüberlauf, wegen dem häufigen erstellen der bmp's
Wenn ich an der "rechenzeit" im "updatehabitat"-Aufruf rumspiel oder vor "SetGadgetState(1,CreateBitmapFromSprite(1))" nochn "delay(etwas)" einsetzte, dauerts unterschiedlich lang, bis ich nur noch'n grauen Button hab.
Oder meinst Du was anders ?