pub type RgbaImage = ImageBuffer<Rgba<u8>, Vec<u8>>;
Expand description
Sendable Rgb + alpha channel image buffer
Aliased Type§
struct RgbaImage { /* private fields */ }
Implementations
source§impl<P, Container> ImageBuffer<P, Container>
impl<P, Container> ImageBuffer<P, Container>
sourcepub fn save_with_format<Q>(
&self,
path: Q,
format: ImageFormat,
) -> ImageResult<()>
pub fn save_with_format<Q>( &self, path: Q, format: ImageFormat, ) -> ImageResult<()>
Saves the buffer to a file at the specified path in the specified format.
See save_buffer_with_format
for
supported types.
source§impl<P, Container> ImageBuffer<P, Container>
impl<P, Container> ImageBuffer<P, Container>
sourcepub fn write_to<W, F>(&self, writer: &mut W, format: F) -> ImageResult<()>
pub fn write_to<W, F>(&self, writer: &mut W, format: F) -> ImageResult<()>
Writes the buffer to a writer in the specified format.
Assumes the writer is buffered. In most cases,
you should wrap your writer in a BufWriter
for best performance.
See ImageOutputFormat
for
supported types.
source§impl<P, Container> ImageBuffer<P, Container>
impl<P, Container> ImageBuffer<P, Container>
sourcepub fn write_with_encoder<E>(&self, encoder: E) -> ImageResult<()>where
E: ImageEncoder,
P: PixelWithColorType,
pub fn write_with_encoder<E>(&self, encoder: E) -> ImageResult<()>where
E: ImageEncoder,
P: PixelWithColorType,
Writes the buffer with the given encoder.
source§impl<P, Container> ImageBuffer<P, Container>
impl<P, Container> ImageBuffer<P, Container>
sourcepub fn from_raw(
width: u32,
height: u32,
buf: Container,
) -> Option<ImageBuffer<P, Container>>
pub fn from_raw( width: u32, height: u32, buf: Container, ) -> Option<ImageBuffer<P, Container>>
Constructs a buffer from a generic container
(for example a Vec
or a slice)
Returns None
if the container is not big enough (including when the image dimensions
necessitate an allocation of more bytes than supported by the container).
sourcepub fn as_raw(&self) -> &Container
pub fn as_raw(&self) -> &Container
Returns the underlying raw buffer
sourcepub fn dimensions(&self) -> (u32, u32)
pub fn dimensions(&self) -> (u32, u32)
The width and height of this image.
sourcepub fn pixels(&self) -> Pixels<'_, P> ⓘ
pub fn pixels(&self) -> Pixels<'_, P> ⓘ
Returns an iterator over the pixels of this image. The iteration order is x = 0 to width then y = 0 to height
sourcepub fn rows(&self) -> Rows<'_, P> ⓘ
pub fn rows(&self) -> Rows<'_, P> ⓘ
Returns an iterator over the rows of this image.
Only non-empty rows can be iterated in this manner. In particular the iterator will not
yield any item when the width of the image is 0
or a pixel type without any channels is
used. This ensures that its length can always be represented by usize
.
sourcepub fn enumerate_pixels(&self) -> EnumeratePixels<'_, P> ⓘ
pub fn enumerate_pixels(&self) -> EnumeratePixels<'_, P> ⓘ
Enumerates over the pixels of the image. The iterator yields the coordinates of each pixel along with a reference to them. The iteration order is x = 0 to width then y = 0 to height Starting from the top left.
sourcepub fn enumerate_rows(&self) -> EnumerateRows<'_, P> ⓘ
pub fn enumerate_rows(&self) -> EnumerateRows<'_, P> ⓘ
Enumerates over the rows of the image. The iterator yields the y-coordinate of each row along with a reference to them.
sourcepub fn get_pixel(&self, x: u32, y: u32) -> &P
pub fn get_pixel(&self, x: u32, y: u32) -> &P
Gets a reference to the pixel at location (x, y)
§Panics
Panics if (x, y)
is out of the bounds (width, height)
.
sourcepub fn get_pixel_checked(&self, x: u32, y: u32) -> Option<&P>
pub fn get_pixel_checked(&self, x: u32, y: u32) -> Option<&P>
Gets a reference to the pixel at location (x, y)
or returns None
if
the index is out of the bounds (width, height)
.
sourcepub fn sample_layout(&self) -> SampleLayout
pub fn sample_layout(&self) -> SampleLayout
Get the format of the buffer when viewed as a matrix of samples.
sourcepub fn into_flat_samples(self) -> FlatSamples<Container>
pub fn into_flat_samples(self) -> FlatSamples<Container>
Return the raw sample buffer with its stride an dimension information.
The returned buffer is guaranteed to be well formed in all cases. It is laid out by
colors, width then height, meaning channel_stride <= width_stride <= height_stride
. All
strides are in numbers of elements but those are mostly u8
in which case the strides are
also byte strides.
sourcepub fn as_flat_samples(&self) -> FlatSamples<&[P::Subpixel]>
pub fn as_flat_samples(&self) -> FlatSamples<&[P::Subpixel]>
Return a view on the raw sample buffer.
See into_flat_samples
for more details.
sourcepub fn as_flat_samples_mut(&mut self) -> FlatSamples<&mut [P::Subpixel]>
pub fn as_flat_samples_mut(&mut self) -> FlatSamples<&mut [P::Subpixel]>
Return a mutable view on the raw sample buffer.
See into_flat_samples
for more details.
source§impl<P, Container> ImageBuffer<P, Container>
impl<P, Container> ImageBuffer<P, Container>
sourcepub fn pixels_mut(&mut self) -> PixelsMut<'_, P> ⓘ
pub fn pixels_mut(&mut self) -> PixelsMut<'_, P> ⓘ
Returns an iterator over the mutable pixels of this image.
sourcepub fn rows_mut(&mut self) -> RowsMut<'_, P> ⓘ
pub fn rows_mut(&mut self) -> RowsMut<'_, P> ⓘ
Returns an iterator over the mutable rows of this image.
Only non-empty rows can be iterated in this manner. In particular the iterator will not
yield any item when the width of the image is 0
or a pixel type without any channels is
used. This ensures that its length can always be represented by usize
.
sourcepub fn enumerate_pixels_mut(&mut self) -> EnumeratePixelsMut<'_, P> ⓘ
pub fn enumerate_pixels_mut(&mut self) -> EnumeratePixelsMut<'_, P> ⓘ
Enumerates over the pixels of the image. The iterator yields the coordinates of each pixel along with a mutable reference to them.
sourcepub fn enumerate_rows_mut(&mut self) -> EnumerateRowsMut<'_, P> ⓘ
pub fn enumerate_rows_mut(&mut self) -> EnumerateRowsMut<'_, P> ⓘ
Enumerates over the rows of the image. The iterator yields the y-coordinate of each row along with a mutable reference to them.
sourcepub fn get_pixel_mut(&mut self, x: u32, y: u32) -> &mut P
pub fn get_pixel_mut(&mut self, x: u32, y: u32) -> &mut P
Gets a reference to the mutable pixel at location (x, y)
§Panics
Panics if (x, y)
is out of the bounds (width, height)
.
source§impl<P, Container> ImageBuffer<P, Container>
impl<P, Container> ImageBuffer<P, Container>
sourcepub fn save<Q>(&self, path: Q) -> ImageResult<()>
pub fn save<Q>(&self, path: Q) -> ImageResult<()>
Saves the buffer to a file at the path specified.
The image format is derived from the file extension.
source§impl<P: Pixel> ImageBuffer<P, Vec<P::Subpixel>>
impl<P: Pixel> ImageBuffer<P, Vec<P::Subpixel>>
sourcepub fn new(width: u32, height: u32) -> ImageBuffer<P, Vec<P::Subpixel>>
pub fn new(width: u32, height: u32) -> ImageBuffer<P, Vec<P::Subpixel>>
Creates a new image buffer based on a Vec<P::Subpixel>
.
§Panics
Panics when the resulting image is larger than the maximum size of a vector.
sourcepub fn from_pixel(
width: u32,
height: u32,
pixel: P,
) -> ImageBuffer<P, Vec<P::Subpixel>>
pub fn from_pixel( width: u32, height: u32, pixel: P, ) -> ImageBuffer<P, Vec<P::Subpixel>>
Constructs a new ImageBuffer by copying a pixel
§Panics
Panics when the resulting image is larger the the maximum size of a vector.
sourcepub fn from_fn<F>(
width: u32,
height: u32,
f: F,
) -> ImageBuffer<P, Vec<P::Subpixel>>
pub fn from_fn<F>( width: u32, height: u32, f: F, ) -> ImageBuffer<P, Vec<P::Subpixel>>
Constructs a new ImageBuffer by repeated application of the supplied function.
The arguments to the function are the pixel’s x and y coordinates.
§Panics
Panics when the resulting image is larger the the maximum size of a vector.
Trait Implementations§
source§impl From<DynamicImage> for RgbaImage
impl From<DynamicImage> for RgbaImage
source§fn from(value: DynamicImage) -> Self
fn from(value: DynamicImage) -> Self
source§impl<P, Container> Clone for ImageBuffer<P, Container>
impl<P, Container> Clone for ImageBuffer<P, Container>
source§fn clone(&self) -> ImageBuffer<P, Container>
fn clone(&self) -> ImageBuffer<P, Container>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<Container, FromType: Pixel, ToType> ConvertBuffer<ImageBuffer<ToType, Vec<<ToType as Pixel>::Subpixel>>> for ImageBuffer<FromType, Container>
impl<Container, FromType: Pixel, ToType> ConvertBuffer<ImageBuffer<ToType, Vec<<ToType as Pixel>::Subpixel>>> for ImageBuffer<FromType, Container>
source§fn convert(&self) -> ImageBuffer<ToType, Vec<ToType::Subpixel>>
fn convert(&self) -> ImageBuffer<ToType, Vec<ToType::Subpixel>>
§Examples
Convert RGB image to gray image.
use image::buffer::ConvertBuffer;
use image::GrayImage;
let image_path = "examples/fractal.png";
let image = image::open(&image_path)
.expect("Open file failed")
.to_rgba8();
let gray_image: GrayImage = image.convert();
source§impl<P, Container> Default for ImageBuffer<P, Container>
impl<P, Container> Default for ImageBuffer<P, Container>
source§impl<P, Container> Deref for ImageBuffer<P, Container>
impl<P, Container> Deref for ImageBuffer<P, Container>
source§impl<P, Container> DerefMut for ImageBuffer<P, Container>
impl<P, Container> DerefMut for ImageBuffer<P, Container>
source§impl<P, Container> GenericImage for ImageBuffer<P, Container>
impl<P, Container> GenericImage for ImageBuffer<P, Container>
source§unsafe fn unsafe_put_pixel(&mut self, x: u32, y: u32, pixel: P)
unsafe fn unsafe_put_pixel(&mut self, x: u32, y: u32, pixel: P)
Puts a pixel at location (x, y), ignoring bounds checking.
source§fn blend_pixel(&mut self, x: u32, y: u32, p: P)
👎Deprecated since 0.24.0: Use iterator pixels_mut
to blend the pixels directly
fn blend_pixel(&mut self, x: u32, y: u32, p: P)
pixels_mut
to blend the pixels directlyPut a pixel at location (x, y), taking into account alpha channels
DEPRECATED: This method will be removed. Blend the pixel directly instead.
source§fn get_pixel_mut(&mut self, x: u32, y: u32) -> &mut P
fn get_pixel_mut(&mut self, x: u32, y: u32) -> &mut P
get_pixel
and put_pixel
instead.(x, y)
. Indexed from top left. Read moresource§fn put_pixel(&mut self, x: u32, y: u32, pixel: P)
fn put_pixel(&mut self, x: u32, y: u32, pixel: P)
source§fn copy_within(&mut self, source: Rect, x: u32, y: u32) -> bool
fn copy_within(&mut self, source: Rect, x: u32, y: u32) -> bool
source§fn copy_from<O>(&mut self, other: &O, x: u32, y: u32) -> ImageResult<()>where
O: GenericImageView<Pixel = Self::Pixel>,
fn copy_from<O>(&mut self, other: &O, x: u32, y: u32) -> ImageResult<()>where
O: GenericImageView<Pixel = Self::Pixel>,
source§fn sub_image(
&mut self,
x: u32,
y: u32,
width: u32,
height: u32,
) -> SubImage<&mut Self>where
Self: Sized,
fn sub_image(
&mut self,
x: u32,
y: u32,
width: u32,
height: u32,
) -> SubImage<&mut Self>where
Self: Sized,
GenericImageView::view
The coordinates set the position of the top left corner of the SubImage.source§impl<P, Container> GenericImageView for ImageBuffer<P, Container>
impl<P, Container> GenericImageView for ImageBuffer<P, Container>
source§unsafe fn unsafe_get_pixel(&self, x: u32, y: u32) -> P
unsafe fn unsafe_get_pixel(&self, x: u32, y: u32) -> P
Returns the pixel located at (x, y), ignoring bounds checking.
source§fn dimensions(&self) -> (u32, u32)
fn dimensions(&self) -> (u32, u32)
source§fn bounds(&self) -> (u32, u32, u32, u32)
fn bounds(&self) -> (u32, u32, u32, u32)
dimensions
insteadsource§fn get_pixel(&self, x: u32, y: u32) -> P
fn get_pixel(&self, x: u32, y: u32) -> P
source§fn in_bounds(&self, x: u32, y: u32) -> bool
fn in_bounds(&self, x: u32, y: u32) -> bool
source§fn pixels(&self) -> Pixels<'_, Self> ⓘwhere
Self: Sized,
fn pixels(&self) -> Pixels<'_, Self> ⓘwhere
Self: Sized,
source§fn view(&self, x: u32, y: u32, width: u32, height: u32) -> SubImage<&Self>where
Self: Sized,
fn view(&self, x: u32, y: u32, width: u32, height: u32) -> SubImage<&Self>where
Self: Sized,
GenericImage::sub_image
if you need a mutable view instead.
The coordinates set the position of the top left corner of the view.source§impl<P: PartialEq + Pixel, Container: PartialEq> PartialEq for ImageBuffer<P, Container>
impl<P: PartialEq + Pixel, Container: PartialEq> PartialEq for ImageBuffer<P, Container>
source§fn eq(&self, other: &ImageBuffer<P, Container>) -> bool
fn eq(&self, other: &ImageBuffer<P, Container>) -> bool
self
and other
values to be equal, and is used
by ==
.