Skip to content

How to render a picture through the data of Vec<u8> #13857

Closed Answered by torsteingrindvik
schizobulia asked this question in Q&A
Discussion options

You must be logged in to vote

Here is some code I've used to take image data and create an image of it:

fn foo(assets: Res<AssetServer>, ..) {
    ..
    let image = Image::new( 
        Extent3d { width, height, depth_or_array_layers: 1 },
        TextureDimension::D2,
        data,
        bevy::render::render_resource::TextureFormat::Rgba8UnormSrgb,
        RenderAssetUsages::default(),
    );

    let image_handle: Handle<Image> = assets.add(image);

    // Can now use this handle in e.g. a standard material
}

Since you want UiImage and that has a field for Handle<Image> that should work.

Also the image creation needs data in the correct layout.
Here is one way I've gotten the above to work when using the Image cr…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by schizobulia
Comment options

You must be logged in to vote
1 reply
@torsteingrindvik
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #13856 on June 15, 2024 08:07.