Type Alias GrayImage
pub type GrayImage = ImageBuffer<Luma<u8>, Vec<u8>>;
dep_image
only.Expand description
Sendable grayscale image buffer
Aliased Type§
struct GrayImage { /* private fields */ }
Implementations
§impl<P, Container> ImageBuffer<P, Container>
impl<P, Container> ImageBuffer<P, Container>
pub fn par_pixels_mut(&mut self) -> PixelsMutPar<'_, P>
pub fn par_pixels_mut(&mut self) -> PixelsMutPar<'_, P>
Returns a parallel iterator over the mutable pixels of this image, usable with rayon
.
See pixels_mut
for more information.
pub fn par_enumerate_pixels_mut(&mut self) -> EnumeratePixelsMutPar<'_, P>
pub fn par_enumerate_pixels_mut(&mut self) -> EnumeratePixelsMutPar<'_, P>
Returns a parallel iterator over the mutable pixels of this image and their coordinates, usable with rayon
.
See enumerate_pixels_mut
for more information.
§impl<P, Container> ImageBuffer<P, Container>
impl<P, Container> ImageBuffer<P, Container>
pub fn par_pixels(&self) -> PixelsPar<'_, P>
pub fn par_pixels(&self) -> PixelsPar<'_, P>
Returns a parallel iterator over the pixels of this image, usable with rayon
.
See pixels
for more information.
pub fn par_enumerate_pixels(&self) -> EnumeratePixelsPar<'_, P>
pub fn par_enumerate_pixels(&self) -> EnumeratePixelsPar<'_, P>
Returns a parallel iterator over the pixels of this image and their coordinates, usable with rayon
.
See enumerate_pixels
for more information.
§impl<P, Container> ImageBuffer<P, Container>
impl<P, Container> ImageBuffer<P, Container>
pub 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.
pub 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
.
pub 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.
pub 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.
pub 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)
.
§impl<P, Container> ImageBuffer<P, Container>
impl<P, Container> ImageBuffer<P, Container>
pub 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).
pub fn into_raw(self) -> Container
pub fn into_raw(self) -> Container
Returns the underlying raw buffer
pub fn as_raw(&self) -> &Container
pub fn as_raw(&self) -> &Container
Returns the underlying raw buffer
pub fn dimensions(&self) -> (u32, u32) ⓘ
pub fn dimensions(&self) -> (u32, u32) ⓘ
The width and height of this image.
pub 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
pub 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
.
pub 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.
pub 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.
pub 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)
.
pub 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)
.
pub fn sample_layout(&self) -> SampleLayout
pub fn sample_layout(&self) -> SampleLayout
Get the format of the buffer when viewed as a matrix of samples.
pub 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.
pub fn as_flat_samples(&self) -> FlatSamples<&[<P as Pixel>::Subpixel]>
pub fn as_flat_samples(&self) -> FlatSamples<&[<P as Pixel>::Subpixel]>
Return a view on the raw sample buffer.
See into_flat_samples
for more details.
pub fn as_flat_samples_mut(
&mut self,
) -> FlatSamples<&mut [<P as Pixel>::Subpixel]>
pub fn as_flat_samples_mut( &mut self, ) -> FlatSamples<&mut [<P as Pixel>::Subpixel]>
Return a mutable view on the raw sample buffer.
See into_flat_samples
for more details.
§impl<P, Container> ImageBuffer<P, Container>
impl<P, Container> ImageBuffer<P, Container>
pub fn save<Q>(&self, path: Q) -> Result<(), ImageError> ⓘ
pub fn save<Q>(&self, path: Q) -> Result<(), ImageError> ⓘ
Saves the buffer to a file at the path specified.
The image format is derived from the file extension.
§impl<P, Container> ImageBuffer<P, Container>
impl<P, Container> ImageBuffer<P, Container>
pub fn save_with_format<Q>(
&self,
path: Q,
format: ImageFormat,
) -> Result<(), ImageError> ⓘ
pub fn save_with_format<Q>( &self, path: Q, format: ImageFormat, ) -> Result<(), ImageError> ⓘ
Saves the buffer to a file at the specified path in the specified format.
See save_buffer_with_format
for
supported types.
§impl<P, Container> ImageBuffer<P, Container>
impl<P, Container> ImageBuffer<P, Container>
pub fn write_to<W>(
&self,
writer: &mut W,
format: ImageFormat,
) -> Result<(), ImageError> ⓘ
pub fn write_to<W>( &self, writer: &mut W, format: ImageFormat, ) -> Result<(), ImageError> ⓘ
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.
§impl<P, Container> ImageBuffer<P, Container>
impl<P, Container> ImageBuffer<P, Container>
pub fn write_with_encoder<E>(&self, encoder: E) -> Result<(), ImageError> ⓘwhere
E: ImageEncoder,
P: PixelWithColorType,
pub fn write_with_encoder<E>(&self, encoder: E) -> Result<(), ImageError> ⓘwhere
E: ImageEncoder,
P: PixelWithColorType,
Writes the buffer with the given encoder.
§impl<P> ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>
impl<P> ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>
pub fn from_par_fn<F>(
width: u32,
height: u32,
f: F,
) -> ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>
pub fn from_par_fn<F>( width: u32, height: u32, f: F, ) -> ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>
Constructs a new ImageBuffer
by repeated application of the supplied function,
utilizing multi-threading via rayon
.
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.
§impl<P> ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>where
P: Pixel,
impl<P> ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>where
P: Pixel,
pub fn new(
width: u32,
height: u32,
) -> ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>
pub fn new( width: u32, height: u32, ) -> ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>
Creates a new image buffer based on a Vec<P::Subpixel>
.
all the pixels of this image have a value of zero, regardless of the data type or number of channels.
§Panics
Panics when the resulting image is larger than the maximum size of a vector.
pub fn from_pixel(
width: u32,
height: u32,
pixel: P,
) -> ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>
pub fn from_pixel( width: u32, height: u32, pixel: P, ) -> ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>
Constructs a new ImageBuffer
by copying a pixel
§Panics
Panics when the resulting image is larger the the maximum size of a vector.
pub fn from_fn<F>(
width: u32,
height: u32,
f: F,
) -> ImageBuffer<P, Vec<<P as Pixel>::Subpixel>>
pub fn from_fn<F>( width: u32, height: u32, f: F, ) -> ImageBuffer<P, Vec<<P as Pixel>::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
§impl<P, Container> Clone for ImageBuffer<P, Container>
impl<P, Container> Clone for ImageBuffer<P, Container>
§fn clone(&self) -> ImageBuffer<P, Container>
fn clone(&self) -> ImageBuffer<P, Container>
§fn clone_from(&mut self, source: &ImageBuffer<P, Container>)
fn clone_from(&mut self, source: &ImageBuffer<P, Container>)
source
. Read more§impl<Container, FromType, ToType> ConvertBuffer<ImageBuffer<ToType, Vec<<ToType as Pixel>::Subpixel>>> for ImageBuffer<FromType, Container>
impl<Container, FromType, ToType> ConvertBuffer<ImageBuffer<ToType, Vec<<ToType as Pixel>::Subpixel>>> for ImageBuffer<FromType, Container>
§fn convert(&self) -> ImageBuffer<ToType, Vec<<ToType as Pixel>::Subpixel>>
fn convert(&self) -> ImageBuffer<ToType, Vec<<ToType as Pixel>::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();
§impl<P, Container> Debug for ImageBuffer<P, Container>
impl<P, Container> Debug for ImageBuffer<P, Container>
§impl<P, Container> Default for ImageBuffer<P, Container>
impl<P, Container> Default for ImageBuffer<P, Container>
§fn default() -> ImageBuffer<P, Container>
fn default() -> ImageBuffer<P, Container>
§impl<P, Container> Deref for ImageBuffer<P, Container>
impl<P, Container> Deref for ImageBuffer<P, Container>
§impl<P, Container> DerefMut for ImageBuffer<P, Container>
impl<P, Container> DerefMut for ImageBuffer<P, Container>
§fn deref_mut(&mut self) -> &mut <ImageBuffer<P, Container> as Deref>::Target
fn deref_mut(&mut self) -> &mut <ImageBuffer<P, Container> as Deref>::Target
§impl From<DynamicImage> for ImageBuffer<Luma<u8>, Vec<u8>>
impl From<DynamicImage> for ImageBuffer<Luma<u8>, Vec<u8>>
§fn from(value: DynamicImage) -> ImageBuffer<Luma<u8>, Vec<u8>>
fn from(value: DynamicImage) -> ImageBuffer<Luma<u8>, Vec<u8>>
§impl<P, Container> GenericImage for ImageBuffer<P, Container>
impl<P, Container> GenericImage for ImageBuffer<P, Container>
§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.
§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.
§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 more§fn put_pixel(&mut self, x: u32, y: u32, pixel: P)
fn put_pixel(&mut self, x: u32, y: u32, pixel: P)
§fn copy_within(&mut self, source: Rect, x: u32, y: u32) -> bool
fn copy_within(&mut self, source: Rect, x: u32, y: u32) -> bool
§fn copy_from<O>(&mut self, other: &O, x: u32, y: u32) -> Result<(), ImageError> ⓘwhere
O: GenericImageView<Pixel = Self::Pixel>,
fn copy_from<O>(&mut self, other: &O, x: u32, y: u32) -> Result<(), ImageError> ⓘwhere
O: GenericImageView<Pixel = Self::Pixel>,
§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
.§impl<P, Container> GenericImageView for ImageBuffer<P, Container>
impl<P, Container> GenericImageView for ImageBuffer<P, Container>
§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.