asdf98 commited on
Commit
640d77f
·
verified ·
1 Parent(s): 29cc955

feat: Screen region capture (Shift+S), annotation pen overlay, image grouping, minimap

Browse files
Files changed (1) hide show
  1. src-tauri/src/capture.rs +33 -0
src-tauri/src/capture.rs ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use tauri::{AppHandle, Manager};
2
+ use base64::{engine::general_purpose, Engine as _};
3
+
4
+ /// Capture a region of the screen and return as base64 data URL.
5
+ /// Uses the `screenshots` crate for cross-platform screen capture.
6
+ #[tauri::command]
7
+ pub async fn capture_screen_region(
8
+ app: AppHandle,
9
+ x: i32,
10
+ y: i32,
11
+ width: u32,
12
+ height: u32,
13
+ ) -> Result<String, String> {
14
+ use std::io::Cursor;
15
+
16
+ // Use the primary screen
17
+ let screens = screenshots::Screen::all().map_err(|e| format!("screen list error: {e}"))?;
18
+ let screen = screens.into_iter().next().ok_or("no screen found")?;
19
+
20
+ let capture = screen.capture_area(x, y, width, height)
21
+ .map_err(|e| format!("capture error: {e}"))?;
22
+
23
+ let rgba = capture.rgba();
24
+ let img = image::RgbaImage::from_raw(capture.width(), capture.height(), rgba.to_vec())
25
+ .ok_or("failed to create image from capture")?;
26
+
27
+ let mut buf = Cursor::new(Vec::new());
28
+ img.write_to(&mut buf, image::ImageFormat::Png)
29
+ .map_err(|e| format!("png encode error: {e}"))?;
30
+
31
+ let b64 = general_purpose::STANDARD.encode(buf.into_inner());
32
+ Ok(format!("data:image/png;base64,{b64}"))
33
+ }