Safe Haskell | None |
---|---|
Language | Haskell98 |
SFML.Graphics.Image
- module SFML.Utils
- createImage :: Int -> Int -> IO (Either SFException Image)
- imageFromColor :: Int -> Int -> Color -> IO Image
- imageFromPixels :: Int -> Int -> Ptr a -> IO Image
- imageFromFile :: FilePath -> IO (Maybe Image)
- imageFromMemory :: Ptr a -> Int -> IO (Maybe Image)
- imageFromStream :: InputStream -> IO (Maybe Image)
- copy :: SFCopyable a => a -> IO a
- destroy :: SFResource a => a -> IO ()
- saveImage :: Image -> FilePath -> IO Bool
- imageSize :: Image -> IO Vec2u
- createMaskFromColor :: Image -> Color -> Int -> IO ()
- copyImage' :: Image -> Image -> Int -> Int -> IntRect -> Bool -> IO ()
- setPixel :: Image -> Int -> Int -> Color -> IO ()
- getPixel :: Image -> Int -> Int -> IO Color
- getPixels :: Image -> IO (Ptr a)
- flipHorizontally :: Image -> IO ()
- flipVertically :: Image -> IO ()
Documentation
module SFML.Utils
Create an image.
This image is filled with black pixels.
Create an image and fill it with a unique color.
Arguments
:: Int | Width of the image |
-> Int | Height of the image |
-> Ptr a | Array of pixels to copy to the image |
-> IO Image |
Create an image from an array of pixels.
The pixel array is assumed to contain 32-bits RGBA pixels, and have the given width and height. If not, this is an undefined behaviour.
If pixels is null, an empty image is created.
imageFromFile :: FilePath -> IO (Maybe Image)
Create an image from a file on disk.
Arguments
:: Ptr a | Pointer to the file data in memory |
-> Int | Size of the data to load, in bytes |
-> IO (Maybe Image) |
Create an image from a file in memory.
The supported image formats are bmp, png, tga, jpg, gif, psd, hdr and pic. Some format options are not supported, like progressive jpeg.
If this function fails, the image is left unchanged.
imageFromStream :: InputStream -> IO (Maybe Image)
Create an image from a custom stream.
The supported image formats are bmp, png, tga, jpg, gif, psd, hdr and pic. Some format options are not supported, like progressive jpeg.
If this function fails, the image is left unchanged.
copy :: SFCopyable a => a -> IO a
Copy the given SFML resource.
destroy :: SFResource a => a -> IO ()
Destroy the given SFML resource.
saveImage :: Image -> FilePath -> IO Bool
Save an image to a file on disk.
The format of the image is automatically deduced from the extension. The supported image formats are bmp, png, tga and jpg. The destination file is overwritten if it already exists. This function fails if the image is empty.
Return True
if saving was successful.
Arguments
:: Image | Image object |
-> Color | Color to make transparent |
-> Int | Alpha value to assign to transparent pixels |
-> IO () |
Create a transparency mask from a specified color-key.
This function sets the alpha value of every pixel matching the given color to alpha (0 by default), so that they become transparent.
Arguments
:: Image | Dest image object |
-> Image | Source image to copy |
-> Int | X coordinate of the destination position |
-> Int | Y coordinate of the destination position |
-> IntRect | Sub-rectangle of the source image to copy |
-> Bool | Should the copy take in account the source transparency? |
-> IO () |
Copy pixels from an image onto another
This function does a slow pixel copy and should not be used intensively. It can be used to prepare a complex static image from several others, but if you need this kind of feature in real-time you'd better use sfRenderTexture.
If sourceRect is empty, the whole image is copied. If applyAlpha is set to true, the transparency of source pixels is applied. If it is false, the pixels are copied unchanged with their alpha value.
Arguments
:: Image | Image object |
-> Int | X coordinate of pixel to change |
-> Int | Y coordinate of pixel to change |
-> Color | New color of the pixel |
-> IO () |
Change the color of a pixel in an image.
This function doesn't check the validity of the pixel coordinates, using out-of-range values will result in an undefined behaviour.
Arguments
:: Image | Image object |
-> Int | X coordinate of pixel to get |
-> Int | Y coordinate of pixel to get |
-> IO Color |
Get the color of a pixel in an image.
This function doesn't check the validity of the pixel coordinates, using out-of-range values will result in an undefined behaviour.
getPixels :: Image -> IO (Ptr a)
Get a read-only pointer to the array of pixels of an image.
The returned value points to an array of RGBA pixels made of 8 bits integers components. The size of the array is getWidth() * getHeight() * 4.
Warning: the returned pointer may become invalid if you modify the image, so you should never store it for too long. If the image is empty, a null pointer is returned.
flipHorizontally :: Image -> IO ()
Flip an image horizontally (left - right).
flipVertically :: Image -> IO ()
Flip an image vertically (top - bottom)