/// Render this QR code onto an image.
Render this QR code onto an image.
Render this QR code onto an image .
fn qrcode_to_image(code: QrCode) -> RgbImage {
    let width = code.width() as u32;
    let mut img = RgbImage::new(width+8, width+8); // leaving 4 pixels for the quiet zone
    let colors = code.to_colors();
    let mut colors_iter = colors.iter();
    for x in 4..=(width+4) {
        for y in 4..=(width+4) {
            let pixel = colors_iter.next().unwrap_or(&Color::Light);
            img.put_pixel(x, y, pixel.select(Rgb([0,0,0]), Rgb([255,255,255])));
        }
    }
    img
}
fn qrcode_to_image ( code : QrCode ) -> RgbImage { let width = code . width ( ) as u32 ; let mut img = RgbImage :: new ( width + 8 , width + 8 ) ; // leaving 4 pixels for the quiet zone let colors = code . to_colors ( ) ; let mut colors_iter = colors . iter ( ) ; for x in 4 ..= ( width + 4 ) { for y in 4 ..= ( width + 4 ) { let pixel = colors_iter . next ( ) . unwrap_or ( & Color :: Light ) ; img . put_pixel ( x , y , pixel . select ( Rgb ( [ 0 , 0 , 0 ] ) , Rgb ( [ 255 , 255 , 255 ] ) ) ) ; } } img }
Render this QR code onto an image.
Render this QR code onto an image .
code
QrCode