Wasm32: ImageElement -> Vec<u8> -> some processing -> Vec<u8> -> ImageElement

I have the following problem. I have an stdweb::web::html_element::ImageElement - Rust

I want to take this ImageElement, convert it to a Vec<u8> of (width * height * [r,g,b,a]), do some processing, convert the Vec<u8> back to ImageElement.

This seems surprisingly messy.

Rust solutions shows something like this: javascript - Accessing UInt8ClampedArray in Rust web assembly - Stack Overflow (wtf, wasm32 ffi?)

JS solutions involve "ImageElement -> draw to Canvas -> get ImageData -> manip -> redraw to Canvas -> convert to DataURL -> construct ImageElement"

Is there an easier way to handle this? :slight_smile:

It seems messy because it's a messy problem. Implement the JS solution listed and during the manip step, move the buffer into rust wasm.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.