抖动图像压缩问题

时间:2019-09-22 05:42:57

标签: flutter dart

破坏以下命令:

try {
      RenderRepaintBoundary boundary =
          (_globalKey.currentContext.findRenderObject());

      ui.Image image = await boundary.toImage(pixelRatio: 3.0);
      ByteData byteData =
          await image.toByteData(format: ui.ImageByteFormat.png);
      var pngBytes = byteData.buffer.asUint8List();

      final directory = await getTemporaryDirectory();
      final String dirPath = '${directory.path}';    
      byteData = await  rootBundle.load('assets/images/temp.jpg');
  final file = File('${directory.path}/temp1.jpg');
      await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));

      final String filePath = '$dirPath/temp1.jpg';    
      File file1=File(filePath);
      await file1.writeAsBytes(pngBytes);

      final Uint8List result = await ImageCompressor.compressImage(file1);

    } catch (e) {
        print(e);
        return false;
    }

在Android API 25及更高版本上的commpressImage上出现以下错误:

I/ExifInterface_JNI( 7721): Raw image not detected
W/ExifInterface( 7721): Invalid image: ExifInterface got an unsupported image format file(ExifInterface supports JPEG and some RAW image formats only) or a corrupted JPEG file to ExifInterface.
W/ExifInterface( 7721): java.io.IOException: Invalid marker: 89
W/ExifInterface( 7721):     at android.media.ExifInterface.getJpegAttributes(ExifInterface.java:1835)
W/ExifInterface( 7721):     at android.media.ExifInterface.loadAttributes(ExifInterface.java:1475)
W/ExifInterface( 7721):     at android.media.ExifInterface.<init>(ExifInterface.java:1112)
W/ExifInterface( 7721):     at com.example.flutternativeimage.FlutterNativeImagePlugin.copyExif(FlutterNativeImagePlugin.java:193)
W/ExifInterface( 7721):     at com.example.flutternativeimage.FlutterNativeImagePlugin.onMethodCall(FlutterNativeImagePlugin.java:82)
W/ExifInterface( 7721):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
W/ExifInterface( 7721):     at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
W/ExifInterface( 7721):     at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:643)
W/ExifInterface( 7721):     at android.os.MessageQueue.nativePollOnce(Native Method)
W/ExifInterface( 7721):     at android.os.MessageQueue.next(MessageQueue.java:323)
W/ExifInterface( 7721):     at android.os.Looper.loop(Looper.java:136)
W/ExifInterface( 7721):     at android.app.ActivityThread.main(ActivityThread.java:6119)
W/ExifInterface( 7721):     at java.lang.reflect.Method.invoke(Native Method)
W/ExifInterface( 7721):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
W/ExifInterface( 7721):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
I/ExifInterface_JNI( 7721): Raw image not detected
I/flutter ( 7721): Size 5270

0 个答案:

没有答案