如何在Rust中无损裁剪PNG图片且避免色彩失真?
如何通过脚本无损裁剪PNG图片且避免色彩失真?
我为此问题困扰数日,尝试过Python和Rust中的多种图像编辑方法。看似简单,但找不到能在不导致全图色彩失真的情况下裁剪PNG图片的方式。
我运行了一段来源未知的Rust image crate示例脚本:
use image::GenericImageView; fn main() { // Use the open function to load an image from a Path. // `open` returns a `DynamicImage` on success. let img = image::open("../test.png").unwrap(); // The dimensions method returns the images width and height. println!("dimensions {:?}", img.dimensions()); // The color method returns the image's `ColorType`. println!("{:?}", img.color()); // Write the contents of this image to the Writer in PNG format. img.save("../test copy.png").unwrap(); }
生成的test copy.png比原图小约25%,且明显更暗。
我希望实现仅裁剪图片、不做其他修改的效果。手动用MS Paint很容易做到,但能否通过脚本实现?
编辑补充:已将PNG文件及失真副本上传至代码仓库。
内容的提问来源于stack exchange,提问作者Densaugeo
相关产品推荐
相关产品推荐

