Git Product home page Git Product logo

Comments (3)

fintelia avatar fintelia commented on September 22, 2024

The code you provided never actually decodes the contents of image_data. That's a problem because PngEncoder::write_image takes raw uncompressed pixels (with the layout specified by the color type argument). The data should be exactly 4 * width * height bytes.

from image.

 avatar commented on September 22, 2024

@fintelia Could you give me an example of how to properly decode the png from raw bytes read from the file? I've also tried the following, but with no success:

let img = image::io::Reader::open("/home/mat/Downloads/image.png")
    .unwrap()
    .decode()
    .unwrap();

let image_data = img.as_bytes();
let mut output = Vec::with_capacity(image_data.len());
// if image_sub_type == "png" {
let image = image::codecs::png::PngEncoder::new_with_quality(
    &mut output,
    CompressionType::Fast,
    FilterType::Adaptive,
);

image.write_image(
    image_data,
    img.width(),
    img.height(),
    ColorType::Rgba8,
)?;

from image.

 avatar commented on September 22, 2024

Never mind, I've figured I shall use img.color() and pass it to the color type argument.

from image.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.