feat: 选择功能支持透明模式
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user