[ok] Screen to Image
Publié : ven. 12/juin/2015 17:59
salut
j'essaie d'enregistrer ce que j'affiche sur mon screen sur une image. J4ai donc pensé utilisé drawingbuffer(), mais ça m'enregistre une image toute noire.
Je ne sais pas trop d'où vient le bug ^^.
Si vous avez une idée, ça me serait très utile
.
j'essaie d'enregistrer ce que j'affiche sur mon screen sur une image. J4ai donc pensé utilisé drawingbuffer(), mais ça m'enregistre une image toute noire.
Je ne sais pas trop d'où vient le bug ^^.
Si vous avez une idée, ça me serait très utile

Code : Tout sélectionner
W = 1024
H = 768
UsePNGImageDecoder()
UsePNGImageEncoder()
file$ = OpenFileRequester("Open Image", "","png|*.png",0)
If file$ <> ""
LoadImage(0,file$)
OpenWindow(0, 0, 0, W,H, "Screen to Image", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
InitSprite()
OpenWindowedScreen( WindowID(0),0,0,W,H)
ClearScreen(RGB(200,200,200))
If StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawAlphaImage(ImageID(0),0,0)
StopDrawing()
EndIf
; FlipBuffers()
W = ScreenWidth()
H = ScreenHeight()
Dim ColorR(W*H)
Dim ColorG(W*H)
Dim ColorB(W*H)
If StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_AlphaBlend)
Buffer = DrawingBuffer()
If Buffer <> 0
pixelFormat = DrawingBufferPixelFormat()
lineLength = DrawingBufferPitch();Longueur d'une ligne
;If pixelFormat = #PB_PixelFormat_32Bits_BGR | #PB_PixelFormat_ReversedY
For i = 0 To W - 1
For j = 0 To H - 1
ColorR(i*j) = PeekA(Buffer + 4 * i + j * lineLength)
ColorG(i*j) = PeekA(Buffer + 4 * i + j * lineLength + 1)
ColorB(i*j) = PeekA(Buffer + 4 * i + j * lineLength + 2)
Next j
Next i
;EndIf
EndIf
StopDrawing()
EndIf
CreateImage(1,W,H,32,#PB_Image_Transparent)
If StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Buffer = DrawingBuffer()
If Buffer <> 0
pixelFormat = DrawingBufferPixelFormat()
lineLength = DrawingBufferPitch()
If pixelFormat = #PB_PixelFormat_32Bits_BGR | #PB_PixelFormat_ReversedY
For i = 0 To W - 1
For j = 0 To H - 1
PokeA(Buffer + 4 * i + j * lineLength, ColorB(i*j))
PokeA(Buffer + 4 * i + j * lineLength + 1, ColorG(i*j))
PokeA(Buffer + 4 * i + j * lineLength + 2, ColorR(i*j))
Next j
Next i
EndIf
EndIf
StopDrawing()
EndIf
savefile$ = SaveFileRequester("Save image","", "png|*.png",0)
If savefile$ <> ""
If SaveImage(1,savefile$,#PB_ImagePlugin_PNG)
EndIf
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf