Man sollte eigentlich nur so viel wie nötig StartDrawing()...StopDrawing() im Loop einsetzen.
Hier ein kleiner Test.
(Das mit dem transparenten Image kann aber für andere Zwecke ganz nützlich sein.)
Code: Alles auswählen
InitSprite()
InitKeyboard()
EnableExplicit
UsePNGImageDecoder()
UseJPEGImageDecoder()
UseTGAImageDecoder()
UseGIFImageDecoder()
UseTIFFImageDecoder()
Global fname.s = ""
Global i = 0, j = 0, d1 = 0, d2 = 0
Procedure ByteSwap32(addrLong)
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
!mov rax, [p.v_addrLong]
!mov ecx, [rax]
!bswap ecx
!mov [rax], ecx
CompilerElse
!mov eax, [p.v_addrLong]
!mov ecx, [eax]
!bswap ecx
!mov [eax], ecx
CompilerEndIf
EndProcedure
Procedure.i LoadImageTransparent (hLoadImg, TransparentColorRGB.l)
Protected width,height,pitch,imgbase, x,y, hImg32, *RGBA.Long
width = ImageWidth(hLoadImg)
height = ImageHeight(hLoadImg)
hImg32 = CreateImage(#PB_Any, width, height, 32)
If hImg32 = 0: ProcedureReturn 0: EndIf
If StartDrawing(ImageOutput(hImg32)) = 0
FreeImage(hImg32): ProcedureReturn 0
EndIf
If DrawingBufferPixelFormat() & #PB_PixelFormat_32Bits_RGB
TransparentColorRGB | $FF000000 ;Linux & OSX
Else
ByteSwap32(@TransparentColorRGB) ;Windows
TransparentColorRGB = (TransparentColorRGB >> 8) | $FF000000
EndIf
DrawingMode(#PB_2DDrawing_Default)
DrawImage(ImageID(hLoadImg),0,0,width,height)
pitch = DrawingBufferPitch()
imgbase = DrawingBuffer()
width-1: height-1
For y = 0 To height
*RGBA = imgbase + (y * pitch)
For x = 0 To width
If *RGBA\l = TransparentColorRGB
*RGBA\l = 0
EndIf
*RGBA+4
Next x
Next y
StopDrawing()
ProcedureReturn hImg32
EndProcedure
fname = OpenFileRequester("Wähle ein Bild","", "*.*", 0)
Define hLoadImg = LoadImage(#PB_Any, fname)
ResizeImage(hLoadImg, 100, 100)
Define TransparentColor.l = RGB(255,255,255)
Define hTransparentImg = LoadImageTransparent(hLoadImg, TransparentColor)
If hTransparentImg = 0
Debug "Das Bild konnte nicht geladen werden." : End
EndIf
;FreeImage(hLoadImg)
;Speed-Draw-Test
If OpenScreen(800,600,32,"Draw-Test")
Define hTransparentSpr = CreateSprite(#PB_Any, 100, 100, #PB_Sprite_AlphaBlending)
If hTransparentSpr
If StartDrawing(SpriteOutput(hTransparentSpr))
DrawingMode(#PB_2DDrawing_AlphaClip)
DrawAlphaImage(ImageID(hLoadImg),0,0)
StopDrawing()
EndIf
TransparentSpriteColor(hTransparentSpr, TransparentColor)
Else
Debug "Das Sprite konnte nicht erstellt werden." : End
EndIf
Repeat
ExamineKeyboard()
ClearScreen(RGB(255,255,0))
If Not KeyboardPushed(#PB_Key_All)
If StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(10,10, "Bitte 1 - Taste für Image-Draw oder 2 - Taste für Sprite-Draw gedrückt halten.",RGB(0,0,255))
StopDrawing()
EndIf
EndIf
If KeyboardPushed(#PB_Key_1)
d1 = ElapsedMilliseconds()
If StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_AlphaClip)
For i = 0 To 100
DrawImage(ImageID(hTransparentImg), Random(800,0), Random(600,0))
Next i
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(10,10, Str(ElapsedMilliseconds()-d1),RGB(0,0,0))
StopDrawing()
EndIf
EndIf
If KeyboardPushed(#PB_Key_2)
d2 = ElapsedMilliseconds()
For j = 0 To 100
DisplayTransparentSprite(hTransparentSpr, Random(800,0), Random(600,0))
Next j
If StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(10,10, Str(ElapsedMilliseconds()-d2),RGB(0,0,255))
StopDrawing()
EndIf
EndIf
FlipBuffers()
ClearScreen(RGB(0,0,0))
Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()
EndIf
End