Class OcsfmlGraphics.image

class image : [ `Color of Color.t * int * int
| `Copy of < rep__sf_Image : Image.t; .. >
| `Create of int * int
| `File of string
| `None
| `Stream of OcsfmlSystem.input_stream ] ->
object .. end
Class for loading, manipulating and saving images.

image is an abstraction to manipulate images as bidimensional arrays of pixels.

The class provides functions to load, read, write and save pixels, as well as many other useful functions.

image can handle a unique internal representation of pixels, which is RGBA 32 bits. This means that a pixel must be composed of 8 bits red, green, blue and alpha channels -- just like an color. All the functions that return an array of pixels follow this rule, and all parameters that you pass to image functions (such as loadFromPixels) must use this representation as well.

A image can be copied, but it is a heavy resource and if possible you should always use const references to pass or return them to avoid useless copies.


method affect : (< affect : 'a;
copy : ?srcRect:IntRect.t ->
?alpha:bool -> 'b -> int -> int -> unit;
create_from_color : ?color:Color.t -> int -> int -> unit;
create_from_pixels : OcsfmlWindow.pixel_array_type -> unit;
create_mask_from_color : ?alpha:int -> Color.t -> unit;
destroy : unit; flip_horizontally : unit; flip_vertically : unit;
get_pixel : int -> int -> Color.t;
get_pixels_ptr : OcsfmlWindow.pixel_array_type; get_size : int * int;
load_from_file : string -> bool;
load_from_memory : OcsfmlSystem.raw_data_type -> bool;
load_from_stream : OcsfmlSystem.input_stream -> bool;
rep__sf_Image : Image.t; save_to_file : string -> bool;
set_pixel : int -> int -> Color.t -> unit; .. >
as 'b) ->
unit as 'a
method copy : ?srcRect:IntRect.t -> ?alpha:bool -> 'b -> int -> int -> unit
Copy pixels from another image onto this one.

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 render_texture.

srcRect : Sub-rectangle of the source image to copy.
alpha : Should the copy take in account the source transparency ?
method create_from_color : ?color:Color.t -> int -> int -> unit
Create the image and fill it with a unique color.
color : Fill color.
method create_from_pixels : OcsfmlWindow.pixel_array_type -> unit
method create_mask_from_color : ?alpha:int -> Color.t -> unit
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.

alpha : Alpha value to assign to transparent pixels.
method destroy : unit
method flip_horizontally : unit
Flip the image horizontally (left <-> right).
method flip_vertically : unit
Flip the image vertically (top <-> bottom).
method get_size : int * int
Return the size of the image.
Returns Size in pixels.
method get_pixel : int -> int -> Color.t
Get the color of a pixel.

This function doesn't check the validity of the pixel coordinates, using out-of-range values will result in an undefined ebehaviour.
Returns Color of the pixel at coordinates (x, y).

method get_pixels_ptr : OcsfmlWindow.pixel_array_type
Get a read-only bigarray of pixels.

The returned value is 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.
Returns Read-only bigarray of pixels

method load_from_file : string -> bool
Load the image from a file on disk.

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.
Returns True if loading was successful.

method load_from_memory : OcsfmlSystem.raw_data_type -> bool
method load_from_stream : OcsfmlSystem.input_stream -> bool
Load the 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.
Returns True if loading was successful.

method save_to_file : string -> bool
Save the 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.
Returns True if saving was successful.

method set_pixel : int -> int -> Color.t -> unit
Change the color of a pixel.

This function doesn't check the validity of the pixel coordinates, using out-of-range values will result in an undefined behaviour.