Skip to content
Discussion options

You must be logged in to vote

Currently you'll want to use DynamicImage::copy_from_color_space. It does not change the color representation so you can construct a DynamicImage to be used as a target from an existing buffer, transform in a way that changes both color space and channel representation, and then take back the original buffer.

use image::{DynamicImage, RgbaImage};

fn convert(src: &DynamicImage, buffer: RgbaImage) -> Vec<u8> {
    let mut target = DynamicImage::ImageRgba8(buffer);
    target.set_color_space(image::metadata::Cicp::SRGB);
    target.copy_from_color_space(src, Default::default()).unwrap();

    // Note: we know this does not reallocate, it's `Rgba8`.
    let mut img = target.into_rgba8().into…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@197g
Comment options

197g Nov 19, 2025
Maintainer

@mina86
Comment options

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