sdl2 icon indicating copy to clipboard operation
sdl2 copied to clipboard

Get Pixel information from a Surface

Open Piepoli opened this issue 9 years ago • 3 comments

I would like to get the pixel information of a surface (i.e. I have a surface and coordinates (x,y), I want to get the color of that pixel.

I don't think it is possible with sdl2 bindings as now. Or am I wrong?

Piepoli avatar Jan 29 '16 21:01 Piepoli

@Piepoli The type of a Surface is:

data Surface = Surface (Ptr Raw.Surface) (Maybe (MSV.IOVector Word8))

I think the IOVector of Word8 might be the pixels data. I might be wrong tho.

Rydgel avatar Mar 30 '16 09:03 Rydgel

There's also surfacePixels :: MonadIO m => Surface -> m (Ptr ()), but now I'm wondering what the IOVector @Rydgel mentioned is for. As far as I know when you call createRGBSurfaceFrom you need to pass the IOVector with pixel data.

Apparently there are two 'types' of surfaces, managed and unmanaged. When you use createRGBSurfaceFrom you get managed surface, and the IOVector is there, and if you use createRGBSurface it's Nothing.

BartAdv avatar Mar 30 '16 10:03 BartAdv

So yeah, it's better to use surfacePixels as @BartAdv mentioned.

Rydgel avatar Mar 30 '16 11:03 Rydgel