# Bitmap

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/media/imaging/struct-bitmap/

**struct** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
struct Bitmap
```

Holds a bitmap image.

The types deriving from it (`WriteableBitmap`,
`RenderTargetBitmap`) dereference to
`Bitmap`; the members they override are reached through the deriving type
or through [`IBitmap`](/docs/0.5.0/api/ferroui-base/media/imaging/trait-ibitmap/)/[`IImage`](/docs/0.5.0/api/ferroui-base/media/trait-iimage/) handles.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/imaging/bitmap.rs#L17)

## Members

- [`decode_to_width`](#function-decode_to_width)
- [`decode_to_height`](#function-decode_to_height)
- [`create_scaled_bitmap`](#function-create_scaled_bitmap)
- [`from_file`](#function-from_file)
- [`from_stream`](#function-from_stream)
- [`from_pixels`](#function-from_pixels)
- [`dispose`](#function-dispose)
- [`dpi`](#function-dpi)
- [`size`](#function-size)
- [`pixel_size`](#function-pixel_size)
- [`save_to_file`](#function-save_to_file)
- [`save`](#function-save)
- [`format`](#function-format)
- [`alpha_format`](#function-alpha_format)
- [`copy_pixels`](#function-copy_pixels)
- [`copy_pixels_to_framebuffer`](#function-copy_pixels_to_framebuffer)

<a id="function-decode_to_width"></a>

### decode_to_width

```rust
fn decode_to_width(stream: &mut dyn Read, width: i32, interpolation_mode: BitmapInterpolationMode) -> std::io::Result<Bitmap>
```

Loads a bitmap from a stream, decoded to the specified width
maintaining aspect ratio.

`interpolation_mode` is used should a resize be necessary; upstream
defaults it to high quality.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/imaging/bitmap.rs#L35)

<a id="function-decode_to_height"></a>

### decode_to_height

```rust
fn decode_to_height(stream: &mut dyn Read, height: i32, interpolation_mode: BitmapInterpolationMode) -> std::io::Result<Bitmap>
```

Loads a bitmap from a stream, decoded to the specified height
maintaining aspect ratio.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/imaging/bitmap.rs#L45)

<a id="function-create_scaled_bitmap"></a>

### create_scaled_bitmap

```rust
fn create_scaled_bitmap(self: &Self, destination_size: PixelSize, interpolation_mode: BitmapInterpolationMode) -> Bitmap
```

Creates a bitmap scaled to the specified size from the current
bitmap.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/imaging/bitmap.rs#L55)

<a id="function-from_file"></a>

### from_file

```rust
fn from_file(file_name: &str) -> std::io::Result<Bitmap>
```

Loads a bitmap from a file.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/imaging/bitmap.rs#L68)

<a id="function-from_stream"></a>

### from_stream

```rust
fn from_stream(stream: &mut dyn Read) -> std::io::Result<Bitmap>
```

Loads a bitmap from a stream.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/imaging/bitmap.rs#L73)

<a id="function-from_pixels"></a>

### from_pixels

```rust
fn from_pixels(format: PixelFormat, alpha_format: AlphaFormat, data: &[u8], size: PixelSize, dpi: Vector, stride: i32) -> Bitmap
```

Creates a bitmap from pixel data: `stride * size.height` bytes of
`format`/`alpha_format` pixels.

A format the backend cannot hold is converted to RGBA8888.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/imaging/bitmap.rs#L92)

<a id="function-dispose"></a>

### dispose

```rust
fn dispose(self: &Self)
```

Releases the bitmap's reference to the platform bitmap.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/imaging/bitmap.rs#L135)

<a id="function-dpi"></a>

### dpi

```rust
fn dpi(self: &Self) -> Vector
```

The dots per inch (DPI) of the image.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/imaging/bitmap.rs#L140)

<a id="function-size"></a>

### size

```rust
fn size(self: &Self) -> Size
```

The size of the image, in device independent pixels.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/imaging/bitmap.rs#L145)

<a id="function-pixel_size"></a>

### pixel_size

```rust
fn pixel_size(self: &Self) -> PixelSize
```

The size of the bitmap, in device pixels.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/imaging/bitmap.rs#L150)

<a id="function-save_to_file"></a>

### save_to_file

```rust
fn save_to_file(self: &Self, file_name: &str, options: &BitmapEncoderOptions) -> std::io::Result<()>
```

Saves the bitmap to a file.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/imaging/bitmap.rs#L160)

<a id="function-save"></a>

### save

```rust
fn save(self: &Self, stream: &mut dyn Write, options: &BitmapEncoderOptions) -> std::io::Result<()>
```

Saves the bitmap to a stream.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/imaging/bitmap.rs#L166)

<a id="function-format"></a>

### format

```rust
fn format(self: &Self) -> Option<PixelFormat>
```

The pixel format of the bitmap, if its pixels can be read.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/imaging/bitmap.rs#L171)

<a id="function-alpha_format"></a>

### alpha_format

```rust
fn alpha_format(self: &Self) -> Option<AlphaFormat>
```

The alpha format of the bitmap, if its pixels can be read.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/imaging/bitmap.rs#L176)

<a id="function-copy_pixels"></a>

### copy_pixels

```rust
fn copy_pixels(self: &Self, source_rect: PixelRect, buffer: &mut [u8], stride: i32)
```

Copies the pixels of `source_rect` into `buffer`, whose rows are
`stride` bytes apart. An empty `source_rect` selects the whole
bitmap.

Panics when the pixels of the bitmap cannot be read, when the bitmap
was converted from another pixel format on creation, or when the
rectangle, stride or buffer are out of range.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/imaging/bitmap.rs#L284)

<a id="function-copy_pixels_to_framebuffer"></a>

### copy_pixels_to_framebuffer

```rust
fn copy_pixels_to_framebuffer(self: &Self, buffer: &dyn ILockedFramebuffer)
```

Copies the pixels of the bitmap into a locked framebuffer, converting
them to its pixel and alpha formats.

Panics when the pixels of the bitmap cannot be read.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/imaging/bitmap.rs#L304)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ErasedDestructor`
- `IntoEither`
- [`IImage`](/docs/0.5.0/api/ferroui-base/media/trait-iimage/)
- [`IBitmap`](/docs/0.5.0/api/ferroui-base/media/imaging/trait-ibitmap/)
- [`IImageBrushSource`](/docs/0.5.0/api/ferroui-base/media/trait-iimagebrushsource/)
- `PartialEq`
- [`MarkupTyped`](/docs/0.5.0/api/ferroui-base/metadata/trait-markuptyped/)
- [`ValueTypeRegistration`](/docs/0.5.0/api/ferroui-base/data/core/trait-valuetyperegistration/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
