# WriteableBitmap

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

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

```rust
struct WriteableBitmap
```

Holds a writeable bitmap image.

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

## Members

- [`new`](#function-new)
- [`from_pixels`](#function-from_pixels)
- [`format`](#function-format)
- [`lock`](#function-lock)
- [`copy_pixels`](#function-copy_pixels)
- [`decode`](#function-decode)
- [`decode_to_width`](#function-decode_to_width)
- [`decode_to_height`](#function-decode_to_height)

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

### new

```rust
fn new(size: PixelSize, dpi: Vector, format: Option<PixelFormat>, alpha_format: Option<AlphaFormat>) -> WriteableBitmap
```

Creates a bitmap of the given size, in pixels, and DPI. The formats
default to the backend's default formats.

Panics when the size is not positive or the pixel format is not
supported.

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

<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) -> WriteableBitmap
```

Creates a writeable bitmap from a pixel data copy: `data` holds rows
of `format` pixels, `stride` bytes apart.

Panics when `stride` is too small for a row.

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

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

### format

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

The pixel format of the bitmap.

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

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

### lock

```rust
fn lock(self: &Self) -> Rc<dyn ILockedFramebuffer>
```

Locks the pixel data of the bitmap and returns a framebuffer that can
be used to read and write the pixels. The changes are committed when
the framebuffer is disposed.

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

<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.

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

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

### decode

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

Loads a writeable bitmap from a stream.

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

<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<WriteableBitmap>
```

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

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

<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<WriteableBitmap>
```

Loads a writeable 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/writeable_bitmap.rs#L149)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- [`Receiver`](/docs/0.5.0/api/ferroui-system/task/oneshot/struct-receiver/)
- `Any`
- `ErasedDestructor`
- `IntoEither`
- `Deref`
- [`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/)

## Availability

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