Skip to content

Commit 6e0e0d5

Browse files
fix: avoid error log when DeleteObject succeeds (#195)
* fix: avoid error log when `DeleteObject` returns `true` * chore: bump version * refactor: use function to delete created bitmap
1 parent 66feae0 commit 6e0e0d5

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "xcap"
3-
version = "0.3.2"
3+
version = "0.3.3"
44
edition = "2021"
55
description = "XCap is a cross-platform screen capture library written in Rust. It supports Linux (X11, Wayland), MacOS, and Windows. XCap supports screenshot and video recording (WIP)."
66
license = "Apache-2.0"

src/windows/capture.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ fn to_rgba_image(
6363
bgra_to_rgba_image(width as u32, height as u32, buffer)
6464
}
6565

66+
fn delete_bitmap_object(val: HBITMAP) {
67+
let succeed = unsafe { DeleteObject(val.into()).as_bool() };
68+
69+
if !succeed {
70+
log::error!("DeleteObject {:?} failed", val);
71+
}
72+
}
73+
6674
#[allow(unused)]
6775
pub fn capture_monitor(x: i32, y: i32, width: i32, height: i32) -> XCapResult<RgbaImage> {
6876
unsafe {
@@ -86,11 +94,7 @@ pub fn capture_monitor(x: i32, y: i32, width: i32, height: i32) -> XCapResult<Rg
8694

8795
let scope_guard_h_bitmap = guard(
8896
CreateCompatibleBitmap(*scope_guard_hdc_desktop_window, width, height),
89-
|val| {
90-
if DeleteObject(val.into()).as_bool() {
91-
log::error!("DeleteObject {:?} failed", val);
92-
}
93-
},
97+
delete_bitmap_object,
9498
);
9599

96100
// 使用SelectObject函数将这个位图选择到DC中
@@ -161,11 +165,7 @@ pub fn capture_window(
161165
});
162166
let scope_guard_h_bitmap = guard(
163167
CreateCompatibleBitmap(*scope_guard_hdc_window, width, height),
164-
|val| {
165-
if DeleteObject(val.into()).as_bool() {
166-
log::error!("DeleteObject {:?} failed", val);
167-
}
168-
},
168+
delete_bitmap_object,
169169
);
170170

171171
let previous_object = SelectObject(*scope_guard_hdc_mem, (*scope_guard_h_bitmap).into());

0 commit comments

Comments
 (0)