# [−][src]Struct image::ImageBuffer

    pub struct ImageBuffer<P: Pixel, Container> { /* fields omitted */ }

Generic image buffer

## Methods

### `impl<P, Container> ImageBuffer<P, Container> where
P: Pixel + 'static,
P::Subpixel: 'static,
Container: Deref<Target = [P::Subpixel]>,` [src]

#### `pub fn from_raw(
width: u32,
height: u32,
buf: Container
) -> Option<ImageBuffer<P, Container>>`[src]

Contructs 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`[src]

Returns the underlying raw buffer

#### `pub fn dimensions(&self) -> (u32, u32)`[src]

The width and height of this image.

#### `pub fn width(&self) -> u32`[src]

The width of this image.

#### `pub fn height(&self) -> u32`[src]

The height of this image.

#### `pub fn pixels(&self) -> Pixels<P>`[src]

Returns an iterator over the pixels of this image.

#### `pub fn enumerate_pixels(&self) -> EnumeratePixels<P>`[src]

Enumerates over the pixels of the image. The iterator yields the coordinates of each pixel along with a reference to them.

#### `pub fn get_pixel(&self, x: u32, y: u32) -> &P`[src]

Gets a reference to the pixel at location `(x, y)`

# Panics

Panics if `(x, y)` is out of the bounds `(width, height)`.

#### `pub fn sample_layout(&self) -> SampleLayout`[src]

Get the format of the buffer when viewed as a matrix of samples.

#### `pub fn into_flat_samples(self) -> FlatSamples<Container> where
Container: AsRef<[P::Subpixel]>,` [src]

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 layed 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::Subpixel]> where
Container: AsRef<[P::Subpixel]>,` [src]

Return a view on the raw sample buffer.

See `flattened` for more details.

### `impl<P, Container> ImageBuffer<P, Container> where
P: Pixel + 'static,
P::Subpixel: 'static,
Container: Deref<Target = [P::Subpixel]> + DerefMut,` [src]

#### `pub fn pixels_mut(&mut self) -> PixelsMut<P>`[src]

Returns an iterator over the mutable pixels of this image.

#### `pub fn enumerate_pixels_mut(&mut self) -> EnumeratePixelsMut<P>`[src]

Enumerates over the pixels of the image. The iterator yields the coordinates of each pixel along with a mutable reference to them.

#### `pub fn get_pixel_mut(&mut self, x: u32, y: u32) -> &mut P`[src]

Gets a reference to the mutable pixel at location `(x, y)`

# Panics

Panics if `(x, y)` is out of the bounds `(width, height)`.

#### `pub fn put_pixel(&mut self, x: u32, y: u32, pixel: P)`[src]

Puts a pixel at location `(x, y)`

# Panics

Panics if `(x, y)` is out of the bounds `(width, height)`.

### `impl<P, Container> ImageBuffer<P, Container> where
P: Pixel<Subpixel = u8> + 'static,
Container: Deref<Target = [u8]>,` [src]

#### `pub fn save<Q>(&self, path: Q) -> Result<()> where
Q: AsRef<Path>,` [src]

Saves the buffer to a file at the path specified.

The image format is derived from the file extension. Currently only jpeg and png files are supported.

### `impl<P: Pixel + 'static> ImageBuffer<P, Vec<P::Subpixel>> where
P::Subpixel: 'static,` [src]

#### `pub fn new(width: u32, height: u32) -> ImageBuffer<P, Vec<P::Subpixel>>`[src]

Creates a new image buffer based on a `Vec<P::Subpixel>`.

# Panics

Panics when the resulting image is larger the the maximum size of a vector.

#### `pub fn from_pixel(
width: u32,
height: u32,
pixel: P
) -> ImageBuffer<P, Vec<P::Subpixel>>`[src]

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::Subpixel>> where
F: FnMut(u32, u32) -> P,` [src]

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.

#### `pub fn from_vec(
width: u32,
height: u32,
buf: Vec<P::Subpixel>
) -> Option<ImageBuffer<P, Vec<P::Subpixel>>>`[src]

Creates an image buffer out of an existing buffer. Returns None if the buffer is not big enough.

#### `pub fn into_vec(self) -> Vec<P::Subpixel>`[src]

Consumes the image buffer and returns the underlying data as an owned buffer

## Trait Implementations

### `impl<'a, 'b, Container, FromType: Pixel + 'static, ToType: Pixel + 'static> ConvertBuffer<ImageBuffer<ToType, Vec<<ToType as Pixel>::Subpixel>>> for ImageBuffer<FromType, Container> where
Container: Deref<Target = [FromType::Subpixel]>,
ToType: FromColor<FromType>,
FromType::Subpixel: 'static,
ToType::Subpixel: 'static,` [src]

#### `fn convert(&self) -> ImageBuffer<ToType, Vec<ToType::Subpixel>>`[src]

Converts `self` to a buffer of type T Read more

### `impl<P, Container> GenericImageView for ImageBuffer<P, Container> where
P: Pixel + 'static,
Container: Deref<Target = [P::Subpixel]> + Deref,
P::Subpixel: 'static,` [src]

#### `type Pixel = P`

The type of pixel.

#### `type InnerImageView = Self`

Underlying image type. This is mainly used by SubImages in order to always have a reference to the original image. This allows for less indirections and it eases the use of nested SubImages. Read more

#### `fn dimensions(&self) -> (u32, u32)`[src]

The width and height of this image.

#### `fn bounds(&self) -> (u32, u32, u32, u32)`[src]

The bounding rectangle of this image.

#### `fn get_pixel(&self, x: u32, y: u32) -> P`[src]

Returns the pixel located at (x, y) Read more

#### `unsafe fn unsafe_get_pixel(&self, x: u32, y: u32) -> P`[src]

Returns the pixel located at (x, y), ignoring bounds checking.

#### `fn inner(&self) -> &Self::InnerImageView`[src]

Returns a reference to the underlying image.

#### `fn width(&self) -> u32`[src]

The width of this image.

#### `fn height(&self) -> u32`[src]

The height of this image.

#### `fn in_bounds(&self, x: u32, y: u32) -> bool`[src]

Returns true if this x, y coordinate is contained inside the image.

####
ⓘImportant traits for Pixels<'a, I>

### Important traits for Pixels<'a, I>

`impl<'a, I: GenericImageView> Iterator for Pixels<'a, I> type Item = (u32, u32, I::Pixel);`
`fn pixels(&self) -> Pixels<Self>`[src]

Returns an Iterator over the pixels of this image. The iterator yields the coordinates of each pixel along with their value Read more

#### `fn view(
&self,
x: u32,
y: u32,
width: u32,
height: u32
) -> SubImage<&Self::InnerImageView>`[src]

Returns an subimage that is an immutable view into this image.

### `impl<P, Container> GenericImage for ImageBuffer<P, Container> where
P: Pixel + 'static,
Container: Deref<Target = [P::Subpixel]> + DerefMut,
P::Subpixel: 'static,` [src]

#### `type InnerImage = Self`

Underlying image type. This is mainly used by SubImages in order to always have a reference to the original image. This allows for less indirections and it eases the use of nested SubImages. Read more

#### `fn get_pixel_mut(&mut self, x: u32, y: u32) -> &mut P`[src]

Gets a reference to the mutable pixel at location `(x, y)` Read more

#### `fn put_pixel(&mut self, x: u32, y: u32, pixel: P)`[src]

Put a pixel at location (x, y) Read more

#### `unsafe fn unsafe_put_pixel(&mut self, x: u32, y: u32, pixel: P)`[src]

Puts a pixel at location (x, y), ignoring bounds checking.

#### `fn blend_pixel(&mut self, x: u32, y: u32, p: P)`[src]

Put a pixel at location (x, y), taking into account alpha channels

DEPRECATED: This method will be removed. Blend the pixel directly instead.

#### `fn inner_mut(&mut self) -> &mut Self::InnerImage`[src]

Returns a mutable reference to the underlying image.

####
ⓘImportant traits for MutPixels<'a, I>

### Important traits for MutPixels<'a, I>

`impl<'a, I: GenericImage + 'a> Iterator for MutPixels<'a, I> where
I::Pixel: 'a,
<I::Pixel as Pixel>::Subpixel: 'a, type Item = (u32, u32, &'a mut I::Pixel);`
`fn pixels_mut(&mut self) -> MutPixels<Self>`[src]

Deprecated:

This cannot be implemented safely in Rust. Please use the image buffer directly.

Returns an Iterator over mutable pixels of this image. The iterator yields the coordinates of each pixel along with a mutable reference to them. Read more

#### `fn copy_from<O>(&mut self, other: &O, x: u32, y: u32) -> bool where
O: GenericImageView<Pixel = Self::Pixel>,` [src]

Copies all of the pixels from another image into this image. Read more

#### `fn sub_image(
&mut self,
x: u32,
y: u32,
width: u32,
height: u32
) -> SubImage<&mut Self::InnerImage>`[src]

Returns a subimage that is a view into this image.

### `impl<P, Container> Clone for ImageBuffer<P, Container> where
P: Pixel,
Container: Deref<Target = [P::Subpixel]> + Clone,` [src]

#### `fn clone(&self) -> ImageBuffer<P, Container>`[src]

Returns a copy of the value. Read more

#### `fn clone_from(&mut self, source: &Self)`1.0.0[src]

Performs copy-assignment from `source`. Read more

### `impl<P, Container> DerefMut for ImageBuffer<P, Container> where
P: Pixel + 'static,
P::Subpixel: 'static,
Container: Deref<Target = [P::Subpixel]> + DerefMut,` [src]

#### `fn deref_mut(&mut self) -> &mut Self::Target`[src]

Mutably dereferences the value.

### `impl<P, Container> Deref for ImageBuffer<P, Container> where
P: Pixel + 'static,
P::Subpixel: 'static,
Container: Deref<Target = [P::Subpixel]>,` [src]

#### `type Target = [P::Subpixel]`

The resulting type after dereferencing.

#### `fn deref(&self) -> &Self::Target`[src]

Dereferences the value.

### `impl<P, Container> Index<(u32, u32)> for ImageBuffer<P, Container> where
P: Pixel + 'static,
P::Subpixel: 'static,
Container: Deref<Target = [P::Subpixel]>,` [src]

#### `type Output = P`

The returned type after indexing.

#### `fn index(&self, (x, y): (u32, u32)) -> &P`[src]

Performs the indexing (`container[index]`) operation.

### `impl<P, Container> IndexMut<(u32, u32)> for ImageBuffer<P, Container> where
P: Pixel + 'static,
P::Subpixel: 'static,
Container: Deref<Target = [P::Subpixel]> + DerefMut,` [src]

#### `fn index_mut(&mut self, (x, y): (u32, u32)) -> &mut P`[src]

Performs the mutable indexing (`container[index]`) operation.

### `impl<P: Debug + Pixel, Container: Debug> Debug for ImageBuffer<P, Container>`[src]

#### `fn fmt(&self, f: &mut Formatter) -> Result`[src]

Formats the value using the given formatter. Read more

## Auto Trait Implementations

### `impl<P, Container> Send for ImageBuffer<P, Container> where
Container: Send,
P: Send,`

### `impl<P, Container> Unpin for ImageBuffer<P, Container> where
Container: Unpin,
P: Unpin,`

### `impl<P, Container> Sync for ImageBuffer<P, Container> where
Container: Sync,
P: Sync,`

### `impl<P, Container> UnwindSafe for ImageBuffer<P, Container> where
Container: UnwindSafe,
P: UnwindSafe,`

### `impl<P, Container> RefUnwindSafe for ImageBuffer<P, Container> where
Container: RefUnwindSafe,
P: RefUnwindSafe,`

## Blanket Implementations

### `impl<T> ToOwned for T where
T: Clone,` [src]

#### `type Owned = T`

The resulting type after obtaining ownership.

#### `fn to_owned(&self) -> T`[src]

Creates owned data from borrowed data, usually by cloning. Read more

#### `fn clone_into(&self, target: &mut T)`[src]

🔬 This is a nightly-only experimental API. (`toowned_clone_into`)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

### `impl<T, U> Into<U> for T where
U: From<T>,` [src]

#### `fn into(self) -> U`[src]

Performs the conversion.

### `impl<T> From<T> for T`[src]

#### `fn from(t: T) -> T`[src]

Performs the conversion.

### `impl<T, U> TryFrom<U> for T where
U: Into<T>,` [src]

#### `type Error = Infallible`

The type returned in the event of a conversion error.

#### `fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>`[src]

Performs the conversion.

### `impl<T, U> TryInto<U> for T where
U: TryFrom<T>,` [src]

#### `type Error = <U as TryFrom<T>>::Error`

The type returned in the event of a conversion error.

#### `fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>`[src]

Performs the conversion.

### `impl<T> BorrowMut<T> for T where
T: ?Sized,` [src]

#### `fn borrow_mut(&mut self) -> &mut T`[src]

Mutably borrows from an owned value. Read more

### `impl<T> Borrow<T> for T where
T: ?Sized,` [src]

#### `fn borrow(&self) -> &T`[src]

Immutably borrows from an owned value. Read more

### `impl<T> Any for T where
T: 'static + ?Sized,` [src]

#### `fn type_id(&self) -> TypeId`[src]

Gets the `TypeId` of `self`. Read more

### `impl<T> SetParameter for T`[src]

#### `fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
T: Parameter<Self>,` [src]

Sets `value` as a parameter of `self`.

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)