pub struct Image { /* private fields */ }
Expand description
Image, pixel data stored in CPU memory (RAM)
Implementations§
Source§impl Image
impl Image
Sourcepub fn format(&self) -> PixelFormat
pub fn format(&self) -> PixelFormat
Data format
Sourcepub fn from_raw_file(
file_name: &str,
width: u32,
height: u32,
format: PixelFormat,
header_size: u32,
) -> Option<Self>
pub fn from_raw_file( file_name: &str, width: u32, height: u32, format: PixelFormat, header_size: u32, ) -> Option<Self>
Load image from RAW file data
Sourcepub fn from_file_anim(file_name: &str) -> Option<(Self, usize)>
pub fn from_file_anim(file_name: &str) -> Option<(Self, usize)>
Load image sequence from file (frames appended to image.data)
Returns the amount of frames in the image.
Sourcepub fn from_memory(
file_data: &[u8],
format: Option<ImageFormat>,
) -> Option<Self>
pub fn from_memory( file_data: &[u8], format: Option<ImageFormat>, ) -> Option<Self>
Load image from memory buffer
If format
is None, it will make an educated guess on the ImageFormat (not all formats are supported for guessing).
Sourcepub fn from_texture(texture: &Texture) -> Option<Self>
pub fn from_texture(texture: &Texture) -> Option<Self>
Load image from GPU texture data
Sourcepub fn from_screen(_raylib: &Raylib) -> Option<Self>
pub fn from_screen(_raylib: &Raylib) -> Option<Self>
Load image from screen buffer and (screenshot)
Sourcepub fn export(&self, file_name: &str) -> bool
pub fn export(&self, file_name: &str) -> bool
Export image data to file, returns true on success
Sourcepub fn export_as_code(&self, file_name: &str) -> bool
pub fn export_as_code(&self, file_name: &str) -> bool
Export image as code file defining an array of bytes, returns true on success
Sourcepub fn generate_color(width: u32, height: u32, color: Color) -> Self
pub fn generate_color(width: u32, height: u32, color: Color) -> Self
Generate image: plain color
Sourcepub fn generate_gradient_vertical(
width: u32,
height: u32,
top: Color,
bottom: Color,
) -> Self
pub fn generate_gradient_vertical( width: u32, height: u32, top: Color, bottom: Color, ) -> Self
Generate image: vertical gradient
Sourcepub fn generate_gradient_horizontal(
width: u32,
height: u32,
left: Color,
right: Color,
) -> Self
pub fn generate_gradient_horizontal( width: u32, height: u32, left: Color, right: Color, ) -> Self
Generate image: horizontal gradient
Sourcepub fn generate_gradient_radial(
width: u32,
height: u32,
density: f32,
inner: Color,
outer: Color,
) -> Self
pub fn generate_gradient_radial( width: u32, height: u32, density: f32, inner: Color, outer: Color, ) -> Self
Generate image: radial gradient
Sourcepub fn generate_checked(
width: u32,
height: u32,
checks_x: u32,
checks_y: u32,
color1: Color,
color2: Color,
) -> Self
pub fn generate_checked( width: u32, height: u32, checks_x: u32, checks_y: u32, color1: Color, color2: Color, ) -> Self
Generate image: checked
Sourcepub fn generate_white_noise(width: u32, height: u32, factor: f32) -> Self
pub fn generate_white_noise(width: u32, height: u32, factor: f32) -> Self
Generate image: white noise
Sourcepub fn generate_perlin_noise(
width: u32,
height: u32,
offset_x: i32,
offset_y: i32,
scale: f32,
) -> Self
pub fn generate_perlin_noise( width: u32, height: u32, offset_x: i32, offset_y: i32, scale: f32, ) -> Self
Generate image: perlin noise
Sourcepub fn generate_cellular(width: u32, height: u32, tile_size: u32) -> Self
pub fn generate_cellular(width: u32, height: u32, tile_size: u32) -> Self
Generate image: cellular algorithm, bigger tileSize means bigger cells
Sourcepub fn generate_text(width: u32, height: u32, text: &str) -> Self
pub fn generate_text(width: u32, height: u32, text: &str) -> Self
Generate image: grayscale image from text data
Sourcepub fn from_other_image(image: Self, rect: Rectangle) -> Self
pub fn from_other_image(image: Self, rect: Rectangle) -> Self
Create an image from another image piece
Sourcepub fn text(text: &str, font_size: u32, color: Color) -> Self
pub fn text(text: &str, font_size: u32, color: Color) -> Self
Create an image from text (default font)
Sourcepub fn text_with_font(
text: &str,
font: &Font,
font_size: f32,
spacing: f32,
tint: Color,
) -> Self
pub fn text_with_font( text: &str, font: &Font, font_size: f32, spacing: f32, tint: Color, ) -> Self
Create an image from text (custom sprite font)
Sourcepub fn convert_to_format(&mut self, new_format: PixelFormat)
pub fn convert_to_format(&mut self, new_format: PixelFormat)
Convert image data to desired format
Sourcepub fn convert_to_power_of_two(&mut self, fill: Color)
pub fn convert_to_power_of_two(&mut self, fill: Color)
Convert image to POT (power-of-two)
Sourcepub fn alpha_crop(&mut self, threshold: f32)
pub fn alpha_crop(&mut self, threshold: f32)
Crop image depending on alpha value
Sourcepub fn alpha_clear(&mut self, color: Color, threshold: f32)
pub fn alpha_clear(&mut self, color: Color, threshold: f32)
Clear alpha channel to desired color
Sourcepub fn alpha_mask(&mut self, alpha_mask: &Image)
pub fn alpha_mask(&mut self, alpha_mask: &Image)
Apply alpha mask to image
Sourcepub fn alpha_premultiply(&mut self)
pub fn alpha_premultiply(&mut self)
Premultiply alpha channel
Sourcepub fn blur_gaussian(&mut self, blur_size: u32)
pub fn blur_gaussian(&mut self, blur_size: u32)
Apply Gaussian blur using a box blur approximation
Sourcepub fn resize(&mut self, new_width: u32, new_height: u32)
pub fn resize(&mut self, new_width: u32, new_height: u32)
Resize image (Bicubic scaling algorithm)
Sourcepub fn resize_nn(&mut self, new_width: u32, new_height: u32)
pub fn resize_nn(&mut self, new_width: u32, new_height: u32)
Resize image (Nearest-Neighbor scaling algorithm)
Sourcepub fn resize_canvas(
&mut self,
new_width: u32,
new_height: u32,
offset_x: i32,
offset_y: i32,
fill: Color,
)
pub fn resize_canvas( &mut self, new_width: u32, new_height: u32, offset_x: i32, offset_y: i32, fill: Color, )
Resize canvas and fill with color
Sourcepub fn compute_mipmaps(&mut self)
pub fn compute_mipmaps(&mut self)
Compute all mipmap levels for a provided image
Sourcepub fn dither(&mut self, r_bpp: u32, g_bpp: u32, b_bpp: u32, a_bpp: u32)
pub fn dither(&mut self, r_bpp: u32, g_bpp: u32, b_bpp: u32, a_bpp: u32)
Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
Sourcepub fn flip_vertical(&mut self)
pub fn flip_vertical(&mut self)
Flip image vertically
Sourcepub fn flip_horizontal(&mut self)
pub fn flip_horizontal(&mut self)
Flip image horizontally
Sourcepub fn rotate_clockwise(&mut self)
pub fn rotate_clockwise(&mut self)
Rotate image clockwise 90deg
Sourcepub fn rotate_counter_clockwise(&mut self)
pub fn rotate_counter_clockwise(&mut self)
Rotate image counter-clockwise 90deg
Sourcepub fn color_tint(&mut self, color: Color)
pub fn color_tint(&mut self, color: Color)
Modify image color: tint
Sourcepub fn color_invert(&mut self)
pub fn color_invert(&mut self)
Modify image color: invert
Sourcepub fn color_grayscale(&mut self)
pub fn color_grayscale(&mut self)
Modify image color: grayscale
Sourcepub fn color_contrast(&mut self, contrast: f32)
pub fn color_contrast(&mut self, contrast: f32)
Modify image color: contrast (-100 to 100)
Sourcepub fn color_brightness(&mut self, brightness: i32)
pub fn color_brightness(&mut self, brightness: i32)
Modify image color: brightness (-255 to 255)
Sourcepub fn color_replace(&mut self, color: Color, replace: Color)
pub fn color_replace(&mut self, color: Color, replace: Color)
Modify image color: replace color
Sourcepub fn load_colors(&self) -> Vec<Color>
pub fn load_colors(&self) -> Vec<Color>
Load color data from image as a Color array (RGBA - 32bit)
Sourcepub fn load_palette(&self, max_size: usize) -> Vec<Color>
pub fn load_palette(&self, max_size: usize) -> Vec<Color>
Load colors palette from image as a Color array (RGBA - 32bit)
Sourcepub fn get_alpha_border(&self, threshold: f32) -> Rectangle
pub fn get_alpha_border(&self, threshold: f32) -> Rectangle
Get image alpha border rectangle
Sourcepub fn clear_background(&mut self, color: Color)
pub fn clear_background(&mut self, color: Color)
Clear image background with given color
Sourcepub fn draw_pixel(&mut self, pos: Vector2, color: Color)
pub fn draw_pixel(&mut self, pos: Vector2, color: Color)
Draw pixel within an image
Sourcepub fn draw_line(&mut self, start: Vector2, end: Vector2, color: Color)
pub fn draw_line(&mut self, start: Vector2, end: Vector2, color: Color)
Draw line within an image
Sourcepub fn draw_circle(&mut self, center: Vector2, radius: u32, color: Color)
pub fn draw_circle(&mut self, center: Vector2, radius: u32, color: Color)
Draw a filled circle within an image
Sourcepub fn draw_circle_lines_v(
&mut self,
center: Vector2,
radius: u32,
color: Color,
)
pub fn draw_circle_lines_v( &mut self, center: Vector2, radius: u32, color: Color, )
Draw circle outline within an image
Sourcepub fn draw_rectangle(&mut self, rect: Rectangle, color: Color)
pub fn draw_rectangle(&mut self, rect: Rectangle, color: Color)
Draw rectangle within an image
Sourcepub fn draw_rectangle_lines(
&mut self,
rect: Rectangle,
thickness: u32,
color: Color,
)
pub fn draw_rectangle_lines( &mut self, rect: Rectangle, thickness: u32, color: Color, )
Draw rectangle lines within an image
Sourcepub fn draw_image(
&mut self,
source: &Image,
source_rect: Rectangle,
dest_rect: Rectangle,
tint: Color,
)
pub fn draw_image( &mut self, source: &Image, source_rect: Rectangle, dest_rect: Rectangle, tint: Color, )
Draw a source image within a destination image (tint applied to source)
Sourcepub fn draw_text(
&mut self,
text: &str,
position: Vector2,
font_size: u32,
color: Color,
)
pub fn draw_text( &mut self, text: &str, position: Vector2, font_size: u32, color: Color, )
Draw text (using default font) within an image (destination)
Sourcepub fn draw_text_with_font(
&mut self,
text: &str,
pos: Vector2,
font: &Font,
font_size: f32,
spacing: f32,
tint: Color,
)
pub fn draw_text_with_font( &mut self, text: &str, pos: Vector2, font: &Font, font_size: f32, spacing: f32, tint: Color, )
Draw text (custom sprite font) within an image (destination)
Sourcepub fn get_pixel_data_size(&self) -> usize
pub fn get_pixel_data_size(&self) -> usize
Get pixel data size in bytes for this image
Sourcepub fn rectangle(&self) -> Rectangle
pub fn rectangle(&self) -> Rectangle
Returns a rectangle with x = 0, y = 0; width and height correspond to image’s dimensions
Sourcepub fn as_raw(&self) -> &Image
pub fn as_raw(&self) -> &Image
Get the ‘raw’ ffi type Take caution when cloning so it doesn’t outlive the original
Sourcepub fn as_raw_mut(&mut self) -> &mut Image
pub fn as_raw_mut(&mut self) -> &mut Image
Get the ‘raw’ ffi type Take caution when cloning so it doesn’t outlive the original