mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-12 11:06:57 +00:00
flutter_desktop: cursor image cache mismatch
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
49
flutter/lib/utils/image.dart
Normal file
49
flutter/lib/utils/image.dart
Normal file
@@ -0,0 +1,49 @@
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
Future<ui.Image> decodeImageFromPixels(
|
||||
Uint8List pixels,
|
||||
int width,
|
||||
int height,
|
||||
ui.PixelFormat format, {
|
||||
int? rowBytes,
|
||||
int? targetWidth,
|
||||
int? targetHeight,
|
||||
bool allowUpscaling = true,
|
||||
}) async {
|
||||
if (targetWidth != null) {
|
||||
assert(allowUpscaling || targetWidth <= width);
|
||||
}
|
||||
if (targetHeight != null) {
|
||||
assert(allowUpscaling || targetHeight <= height);
|
||||
}
|
||||
|
||||
final ui.ImmutableBuffer buffer =
|
||||
await ui.ImmutableBuffer.fromUint8List(pixels);
|
||||
final ui.ImageDescriptor descriptor = ui.ImageDescriptor.raw(
|
||||
buffer,
|
||||
width: width,
|
||||
height: height,
|
||||
rowBytes: rowBytes,
|
||||
pixelFormat: format,
|
||||
);
|
||||
if (!allowUpscaling) {
|
||||
if (targetWidth != null && targetWidth! > descriptor.width) {
|
||||
targetWidth = descriptor.width;
|
||||
}
|
||||
if (targetHeight != null && targetHeight! > descriptor.height) {
|
||||
targetHeight = descriptor.height;
|
||||
}
|
||||
}
|
||||
|
||||
final ui.Codec codec = await descriptor.instantiateCodec(
|
||||
targetWidth: targetWidth,
|
||||
targetHeight: targetHeight,
|
||||
);
|
||||
|
||||
final ui.FrameInfo frameInfo = await codec.getNextFrame();
|
||||
codec.dispose();
|
||||
buffer.dispose();
|
||||
descriptor.dispose();
|
||||
return frameInfo.image;
|
||||
}
|
||||
Reference in New Issue
Block a user