#Spawning a SVG in Bevy

16 messages · Page 1 of 1 (latest)

sly quartz
#

I have a String that I want to convert to a QRCode and display in Bevy. I was previously making an SVG and using bevy_egui but I'm working off bevy main in anticipation for the big changes coming with v0.11.
bevy_egui doesn't support main branch of bevy, so I was wondering what is the best current way to do this.

What could I add to this to have an example like this work with bevy main?

pub fn spawn_qr_code(mut commands: Commands, invoice_data: Res<InvoiceDataFromServer>) {
    info!("spawning QR code");
    let invoice_str = &invoice_data.invoice;
    let qr_code = QrCode::with_version(invoice_str, Version::Normal(9), EcLevel::L).unwrap();

    let image = qr_code
        .render::<svg::Color>()
        .min_dimensions(200, 200)
        .max_dimensions(300, 300)
        .dark_color(svg::Color("#800000"))
        .light_color(svg::Color("#ffff80"))
        .build();

    let a = egui_extras::RetainedImage::from_svg_bytes_with_size(
        "invoicesvg",
        image.as_bytes(),
        egui_extras::image::FitTo::Original,
    )
    .unwrap();

    // Cache QR code to be used later
    commands.insert_resource(MyQr(a))
}

Or if not SVG, i guess loading a picture from bytes dynamically.. however.. im not necessarily tied to svg format if another method is easier

cerulean aurora
#

You could use resvg and render it to an Image

sly quartz
cerulean aurora
#

yep

#

oh

#

I didn't read the last part

#

It's probably easier to render the image as a png instead of svg

sly quartz
#

i was unable to figure out how to use image bundle for an in memory png @cerulean aurora

#

i worked many hours trying to figure it out.. i was probably close.. but didn't get it 😓

#

seems that most of the examples were loading png's from physical files

sly quartz
# cerulean aurora what were you stuck on?

i was stuck on properly getting the image to show up. I created a vec<8> for the png or something and when using that with image bundle.. nothing showed in my ui.. i can't quite remember from june26th.. is there an example of creating an arbitary png and feeding that into an image bundle?

cerulean aurora
#

that's very odd

sly quartz
#

i got past it by just patching egui_bevy for 11-dev of bevy