Skip to content

Commit

Permalink
fix: avoid error log when DeleteObject succeeds (#195)
Browse files Browse the repository at this point in the history
* fix: avoid error log when `DeleteObject` returns `true`

* chore: bump version

* refactor: use function to delete created bitmap
  • Loading branch information
ologbonowiwi authored Feb 21, 2025
1 parent 66feae0 commit 6e0e0d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xcap"
version = "0.3.2"
version = "0.3.3"
edition = "2021"
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)."
license = "Apache-2.0"
Expand Down
20 changes: 10 additions & 10 deletions src/windows/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ fn to_rgba_image(
bgra_to_rgba_image(width as u32, height as u32, buffer)
}

fn delete_bitmap_object(val: HBITMAP) {
let succeed = unsafe { DeleteObject(val.into()).as_bool() };

if !succeed {
log::error!("DeleteObject {:?} failed", val);
}
}

#[allow(unused)]
pub fn capture_monitor(x: i32, y: i32, width: i32, height: i32) -> XCapResult<RgbaImage> {
unsafe {
Expand All @@ -86,11 +94,7 @@ pub fn capture_monitor(x: i32, y: i32, width: i32, height: i32) -> XCapResult<Rg

let scope_guard_h_bitmap = guard(
CreateCompatibleBitmap(*scope_guard_hdc_desktop_window, width, height),
|val| {
if DeleteObject(val.into()).as_bool() {
log::error!("DeleteObject {:?} failed", val);
}
},
delete_bitmap_object,
);

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

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

0 comments on commit 6e0e0d5

Please sign in to comment.