mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-18 19:02:34 +01:00
Merge branch 'krille/fix-image-sending' into 'main'
fix: Image sending See merge request famedly/fluffychat!808
This commit is contained in:
commit
7e0bcf5629
@ -1,3 +1,6 @@
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:native_imaging/native_imaging.dart' as native;
|
||||
|
||||
@ -6,8 +9,28 @@ Future<MatrixImageFileResizedResponse?> customImageResizer(
|
||||
await native.init();
|
||||
var nativeImg = await native.Image.loadEncoded(arguments.bytes);
|
||||
|
||||
try {
|
||||
nativeImg = await native.Image.loadEncoded(arguments.bytes); // load on web
|
||||
} on UnsupportedError {
|
||||
// for the other platforms
|
||||
final dartCodec = await instantiateImageCodec(arguments.bytes);
|
||||
final dartFrame = await dartCodec.getNextFrame();
|
||||
final rgbaData = await dartFrame.image.toByteData();
|
||||
if (rgbaData == null) {
|
||||
return null;
|
||||
}
|
||||
final rgba = Uint8List.view(
|
||||
rgbaData.buffer, rgbaData.offsetInBytes, rgbaData.lengthInBytes);
|
||||
dartFrame.image.dispose();
|
||||
dartCodec.dispose();
|
||||
|
||||
nativeImg = native.Image.fromRGBA(
|
||||
dartFrame.image.width, dartFrame.image.height, rgba);
|
||||
}
|
||||
|
||||
final width = nativeImg.width;
|
||||
final height = nativeImg.height;
|
||||
|
||||
final max = arguments.maxDimension;
|
||||
if (width > max || height > max) {
|
||||
var w = max, h = max;
|
||||
|
Loading…
Reference in New Issue
Block a user