Skip to content
Discussion options

You must be logged in to vote

Thanks, I just found a way

fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut images: ResMut<Assets<Image>>) {
    let buf = capture_display().unwrap();
    let bitmap_data = buf.pixels.to_vec();
    let texture = Image::new_fill(Extent3d {
        width: 2560,
        height: 1440,
        depth_or_array_layers: 1,
    }, TextureDimension::D2, &bitmap_data, TextureFormat::Rgba8UnormSrgb, RenderAssetUsages::default());

    let texture_handle = images.add(texture);

    commands.spawn(Camera2dBundle::default());
    commands.spawn(SpriteBundle {
        texture: texture_handle,
        ..Default::default()
    });
}

Replies: 1 comment 1 reply

Comment options

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

Answer selected by han1548772930
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