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

I have the following problem. I have an https://docs.rs/stdweb/0.4.20/stdweb/web/html_element/struct.ImageElement.html

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: https://stackoverflow.com/questions/46894766/accessing-uint8clampedarray-in-rust-web-assembly#50849229 (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