Skip to content

An open-source cross-platform alternative to AirDrop

feat: Convert Clipboard image to png (#2092)

Pitchaya Boonsarngsuka3ec31620ddb
diff --git a/app/lib/util/native/file_picker.dart b/app/lib/util/native/file_picker.dart
index 3a27f4c0..bc776dc2 100644
--- a/app/lib/util/native/file_picker.dart
+++ b/app/lib/util/native/file_picker.dart
@@ -6,6 +6,7 @@ import 'package:file_selector/file_selector.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
+import 'package:image/image.dart' as img;
import 'package:localsend_app/config/theme.dart';
import 'package:localsend_app/gen/strings.g.dart';
import 'package:localsend_app/model/cross_file.dart';
@@ -270,11 +271,25 @@ Future<void> _pickClipboard(BuildContext context, Ref ref) async {
return;
}
- final image = await Pasteboard.image;
+ var image = await Pasteboard.image;
if (image != null) {
+ // On Windows, Pasteboard read image from clipboard as BMP which is large and inefficient. Attempt to convert to PNG
+ if (determineImageType(image) == 'bmp') {
+ try {
+ final pngImage = await (img.Command()
+ ..decodeBmp(image)
+ ..encodePng())
+ .getBytesThread();
+ if (pngImage != null) {
+ image = pngImage;
+ }
+ } catch (err) {
+ // Fail to convert to png, proceed with existing bmp
+ }
+ }
final now = DateTime.now();
final fileName =
- 'clipboard_${now.year}-${now.month.twoDigitString}-${now.day.twoDigitString}_${now.hour.twoDigitString}-${now.minute.twoDigitString}.${determineImageType(image)}';
+ 'clipboard_${now.year}-${now.month.twoDigitString}-${now.day.twoDigitString}_${now.hour.twoDigitString}-${now.minute.twoDigitString}.${determineImageType(image!)}';
ref.redux(selectedSendingFilesProvider).dispatch(AddBinaryAction(
bytes: image,
fileType: FileType.image,
diff --git a/app/pubspec.lock b/app/pubspec.lock
index 8d47a710..ce978fb3 100644
--- a/app/pubspec.lock
+++ b/app/pubspec.lock
@@ -666,7 +666,7 @@ packages:
source: hosted
version: "4.0.2"
image:
- dependency: transitive
+ dependency: "direct main"
description:
name: image
sha256: f31d52537dc417fdcde36088fdf11d191026fd5e4fae742491ebd40e5a8bea7d
diff --git a/app/pubspec.yaml b/app/pubspec.yaml
index c0748e92..988d8219 100644
--- a/app/pubspec.yaml
+++ b/app/pubspec.yaml
@@ -29,6 +29,7 @@ dependencies:
sdk: flutter
flutter_markdown: 0.7.4+2
gal: 2.3.0
+ image: ^4.3.0
image_picker: 1.1.2
in_app_purchase: 3.2.0 # [FOSS_REMOVE]
intl: ^0.19.0 # allow newer versions, so it can compile with newer Flutter versions