Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use open_image_from_bytes? #146

Open
xanderjakeq opened this issue Dec 8, 2022 · 3 comments
Open

How to use open_image_from_bytes? #146

xanderjakeq opened this issue Dec 8, 2022 · 3 comments

Comments

@xanderjakeq
Copy link

I have ImageData from the arboard crate to get an image from the clipboard. I want to do something with that image with photon and save it.

I'm trying to use it like this:

open_image_from_bytes(&img_data.to_owned_img().bytes).unwrap()

But I get this error:

OpenError(Unsupported(UnsupportedError { format: Unknown, kind: Format(Unknown) }))

Not sure what I'm doing wrong..

@yosefahab
Copy link

getting the same error when dealing with Video from ffmeg_the_third and Frame from the ffmpeg_frame_grabber
which is probably because ffmpeg returns raw rgb images (no format header), DynamicImage has a method to convert raw images to a specific format,

let mut png_buffer = Vec::new();
image.write_to(&mut Cursor::new(&mut png_buffer), image::ImageOutputFormat::Png,).unwrap();

however it does not seem to work with photon

@nathanbabcock
Copy link
Contributor

@xanderjakeq @yosefahab I wrote this function to do something very similar. Maybe it will help you. The trick is to use the PhotonImage::new() constructor with the raw pixels.

/// Convert an `RgbImage` (`image` crate) to a `PhotonImage` (`photon-rs` crate)
pub fn rgb_to_photon(rgb: &RgbImage) -> PhotonImage {
    let rgb24 = rgb.to_vec();
    let rgb32 = rgb24_to_rgba32(rgb24);

    PhotonImage::new(rgb32, rgb.width(), rgb.height())
}

@yosefahab
Copy link

I'm not sure where you got rgb24_to_rgb32() but this adds too much overhead (bytes -> image -> rgb -> rgb -> photon), it would be much better if we figure out why its not working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants