Git Product home page Git Product logo

Comments (4)

fintelia avatar fintelia commented on September 22, 2024

There is a sign of error. The compiler prints a warning that you're ignoring the return value of save:

warning: unused `Result` that must be used
  --> src/main.rs:16:5
   |
16 |     image.save("before.jpg"); // Doesn't work
   |     ^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this `Result` may be an `Err` variant, which should be handled
   = note: `#[warn(unused_must_use)]` on by default
help: use `let _ = ...` to ignore the resulting value
   |
16 |     let _ = image.save("before.jpg"); // Doesn't work
   |     +++++++

warning: unused `Result` that must be used
  --> src/main.rs:19:5
   |
19 |     image.to_rgb8().save("after.jpg"); // Works!
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this `Result` may be an `Err` variant, which should be handled
help: use `let _ = ...` to ignore the resulting value
   |
19 |     let _ = image.to_rgb8().save("after.jpg"); // Works!
   |     +++++++

(playground link)

If you handle the error by changing your code to image.save("before.jpg").expect("failed to save image") then you can see what the actual problem is:

thread 'main' panicked at 'failed to save image: Unsupported(UnsupportedError { format: Exact(Jpeg), kind: Color(Rgb32F) })', src/main.rs:16:30

In other words, JPEG files cannot hold Rgb32F pixels so your image couldn't be saved using that format.

from image.

JerzySpendel avatar JerzySpendel commented on September 22, 2024

Ah ok, I didn't think about that. Ok then, is that expected behaviour that we cannot save Rgb32F pixels? Maybe we could cast Rgb<f32> to Rgb<u8> implicitly by multiplying by 255?

from image.

fintelia avatar fintelia commented on September 22, 2024

We intentionally don't do that conversion implicitly. However, I believe that's how DynamicImage::into_rgb8 works when called on a Rgb32F image.

from image.

JerzySpendel avatar JerzySpendel commented on September 22, 2024

Ok, thank you for clarification.

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.