Merge pull request #2255 from fufesou/fix_win_cursor_color

fix win cursor color
This commit is contained in:
RustDesk 2022-11-21 19:41:16 +08:00 committed by GitHub
commit 1bddc26b5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -975,7 +975,7 @@ class CursorModel with ChangeNotifier {
final image = await img.decodeImageFromPixels( final image = await img.decodeImageFromPixels(
rgba, width, height, ui.PixelFormat.rgba8888); rgba, width, height, ui.PixelFormat.rgba8888);
_image = image; _image = image;
if (await _updateCache(image, id, width, height)) { if (await _updateCache(rgba, image, id, width, height)) {
_images[id] = Tuple3(image, _hotx, _hoty); _images[id] = Tuple3(image, _hotx, _hoty);
} else { } else {
_hotx = 0; _hotx = 0;
@ -989,22 +989,25 @@ class CursorModel with ChangeNotifier {
} }
} }
Future<bool> _updateCache(ui.Image image, int id, int w, int h) async { Future<bool> _updateCache(
ui.ImageByteFormat imgFormat = ui.ImageByteFormat.png; Uint8List rgba, ui.Image image, int id, int w, int h) async {
Uint8List? data;
img2.Image? imgOrigin;
if (Platform.isWindows) { if (Platform.isWindows) {
imgFormat = ui.ImageByteFormat.rawRgba; imgOrigin = img2.Image.fromBytes(w, h, rgba, format: img2.Format.rgba);
} data = imgOrigin.getBytes(format: img2.Format.bgra);
} else {
ByteData? imgBytes = await image.toByteData(format: imgFormat); ByteData? imgBytes =
await image.toByteData(format: ui.ImageByteFormat.png);
if (imgBytes == null) { if (imgBytes == null) {
return false; return false;
} }
data = imgBytes.buffer.asUint8List();
Uint8List? data = imgBytes.buffer.asUint8List(); }
_cache = CursorData( _cache = CursorData(
peerId: this.id, peerId: this.id,
id: id, id: id,
image: Platform.isWindows ? img2.Image.fromBytes(w, h, data) : null, image: imgOrigin,
scale: 1.0, scale: 1.0,
data: data, data: data,
hotxOrigin: _hotx, hotxOrigin: _hotx,