feat: Convert Clipboard image to png (#2092)

This commit is contained in:
Pitchaya Boonsarngsuk
2024-11-28 13:03:25 +00:00
committed by GitHub
parent 6c5f7ba060
commit a3ec31620d
3 changed files with 19 additions and 3 deletions
+17 -2
View File
@@ -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,
+1 -1
View File
@@ -666,7 +666,7 @@ packages:
source: hosted
version: "4.0.2"
image:
dependency: transitive
dependency: "direct main"
description:
name: image
sha256: f31d52537dc417fdcde36088fdf11d191026fd5e4fae742491ebd40e5a8bea7d
+1
View File
@@ -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