Updating Image
data is not working
#21191
Answered
by
JMS55
MuongKimhong
asked this question in
Q&A
-
I'm trying to update image data with raw data but seem like it's not updating. const WIDTH: u32 = 720;
const HEIGHT: u32 = 1280;
fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
let image = Image::new(
Extent3d {
WIDTH,
HEIGHT,
depth_or_array_layers: 1,
},
TextureDimension::D2,
vec![0u8; (WIDTH * HEIGHT) as usize],
TextureFormat::Rgba8UnormSrgb,
RenderAssetUsages::MAIN_WORLD
);
let texture_handle = images.add(image);
commands.insert_resource(
ImageFrame {
handle: texture_handle.clone(),
index: 0
}
);
commands.spawn(Sprite::from_image(texture_handle));
}
fn updating_image(
channel: Res<Channel>,
mut image_frame: ResMut<ImageFrame>,
mut images: ResMut<Assets<Image>>,
) {
// getting frame
let rx = channel.rx_updates.lock().unwrap();
if let Ok(msg) = rx.try_recv() {
match msg {
ImageResponse::FrameData(data) => {
if let Some(image) = images.get_mut(&image_frame.handle) {
image.data = Some(data.clone()); // not updating
let frame: ImageBuffer<Rgba<u8>, _> =
ImageBuffer::from_raw(720, 1280, data)
.expect("no match");
let name = format!("./frames/{}_frame.png", image_frame.index);
frame.save(&name).expect("failed to save image"); // save no problem
image_frame.index += 1;
}
}
}
}
} NOTE: I originally went with I managed to save the image to disk successfully. What did i do wrong? |
Beta Was this translation helpful? Give feedback.
Answered by
JMS55
Sep 25, 2025
Replies: 1 comment
-
You need to use MAIN_WORLD | RENDER_WORLD for RenderAssetUsages. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
MuongKimhong
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to use MAIN_WORLD | RENDER_WORLD for RenderAssetUsages.