1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 13:50:04 -04:00

eframe: capture a screenshot using Frame::request_screenshot

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
amfaber
2023-03-29 16:34:22 +02:00
committed by GitHub
parent 74d43bfa17
commit 870264b005
11 changed files with 384 additions and 73 deletions

View File

@@ -622,7 +622,7 @@ impl Painter {
}
}
pub fn read_screen_rgba(&self, [w, h]: [u32; 2]) -> Vec<u8> {
pub fn read_screen_rgba(&self, [w, h]: [u32; 2]) -> egui::ColorImage {
let mut pixels = vec![0_u8; (w * h * 4) as usize];
unsafe {
self.gl.read_pixels(
@@ -635,7 +635,14 @@ impl Painter {
glow::PixelPackData::Slice(&mut pixels),
);
}
pixels
let mut flipped = Vec::with_capacity((w * h * 4) as usize);
for row in pixels.chunks_exact((w * 4) as usize).rev() {
flipped.extend_from_slice(bytemuck::cast_slice(row));
}
egui::ColorImage {
size: [w as usize, h as usize],
pixels: flipped,
}
}
pub fn read_screen_rgb(&self, [w, h]: [u32; 2]) -> Vec<u8> {