Closed ldicocco closed 6 months ago
@ldicocco could you add a test for bit_image_from_bytes
method in protocol.rs
please?
I try this:
#[cfg(feature = "graphics")]
#[test]
fn test_bit_image_from_bytes() {
let protocol = Protocol::new(Encoder::default());
let img = image::open("./resources/images/small.jpg").unwrap();
assert_eq!(
protocol
.bit_image_from_bytes(
img.as_bytes(),
BitImageOption::new(None, None, BitImageSize::default()).unwrap(),
)
.unwrap(),
vec![
29, 118, 48, 0, 2, 0, 16, 0, 1, 128, 1, 128, 1, 128, 1, 128, 1, 128, 1, 128, 1, 128, 255, 255, 255,
255, 1, 128, 1, 128, 1, 128, 1, 128, 1, 128, 1, 128, 1, 128
]
);
}
But I have this error Result::unwrap()
on an Err
value: Io("The image format could not be determined")`.
Would you have an example?
img.as_bytes()
gives bytes that are different from the ones in the
original file. I'll do a PR with the test rewritten to use the raw file
content.
On Mon, Feb 26, 2024 at 11:40 AM Fabien @.***> wrote:
I try this:
[cfg(feature = "graphics")]#[test]fn test_bit_image_from_bytes() {
let protocol = Protocol::new(Encoder::default()); let img = image::open("./resources/images/small.jpg").unwrap(); assert_eq!( protocol .bit_image_from_bytes( img.as_bytes(), BitImageOption::new(None, None, BitImageSize::default()).unwrap(), ) .unwrap(), vec![ 29, 118, 48, 0, 2, 0, 16, 0, 1, 128, 1, 128, 1, 128, 1, 128, 1, 128, 1, 128, 1, 128, 255, 255, 255, 255, 1, 128, 1, 128, 1, 128, 1, 128, 1, 128, 1, 128, 1, 128 ] );}
But I have this error Result::unwrap() on an Err value: Io("The image format could not be determined")`.
Would you have an example?
— Reply to this email directly, view it on GitHub https://github.com/fabienbellanger/escpos-rs/pull/9#issuecomment-1963813571, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBBBTSYA6BMVFHR3BVGKQDYVRRC7AVCNFSM6AAAAABDYJILEKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRTHAYTGNJXGE . You are receiving this because you were mentioned.Message ID: @.***>
In some applications an image is not retrieved from a file, but from something like
rust_embed
orbase64
, so a possibility to print an image from bytes is useful.