feat: 选择功能支持透明模式

This commit is contained in:
2026-03-07 16:23:56 +08:00
parent d409c11f50
commit aaa1714f0f
2 changed files with 22 additions and 3 deletions

View File

@@ -270,13 +270,21 @@ impl MSCanvas {
}
}
pub fn select_rect(&self, x: i32, y: i32, w: i32, h: i32) -> RectSelection {
pub fn select_rect(&self, x: i32, y: i32, w: i32, h: i32, is_transparent_white: bool) -> RectSelection {
let mut result = vec![255; (w * h * 4) as usize];
let mut index = 0;
let default_color = if is_transparent_white {
MSColor::ZERO
} else {
MSColor::WHITE
};
for yi in y..(y + h) {
for xi in x..(x + w) {
let color = self.pixel_at(xi, yi).unwrap_or(MSColor::WHITE);
let mut color = self.pixel_at(xi, yi).unwrap_or(default_color);
if is_transparent_white && color == MSColor::WHITE {
color = MSColor::ZERO;
}
result[index] = color.r;
result[index + 1] = color.g;
result[index + 2] = color.b;