2 个版本
| 0.0.2 | 2023 年 5 月 25 日 |
|---|---|
| 0.0.1 | 2023 年 5 月 24 日 |
#371 in 渲染
每月 23 次下载
10KB
237 行
gl-capture
用于在 OpenGL 中捕获屏幕截图的库。
请参阅 examples/basic.rs 以获取完整示例。
let img = unsafe { gl_capture::capture() };
// img.size: (u32, u32)
// img.data: Vec<capture_gl::Rgb>
// Now use e.g. `png` or `image` crate to save the image data to a file
或者,使用 capture_into() 来重复使用相同的图像数据,而不是在每次调用时重新分配。
let mut img = gl_capture::RgbImageData::new(size);
unsafe {
gl_capture::capture_into(&mut img);
}
// img.size: (u32, u32)
// img.data: Vec<capture_gl::Rgb>
还支持其他格式,例如 RgbaImageData,BgrImageData,BgraImageData。
在手动使用 gl::ReadPixels() 时,也可以使用 read_pixels() 或 read_pixels_ptr(),它执行一些额外的检查和设置。
let format = gl_capture::CaptureFormat::Rgb;
let mut data = format.allocate_pixel_data(size);
unsafe {
gl_capture::read_pixels((0, 0), size, format, &mut data);
}
依赖项
~120KB