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:
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user