Skip to content
This repository has been archived by the owner on May 31, 2023. It is now read-only.

I can't compress and resize my PNG image #76

Open
skykz opened this issue Nov 25, 2020 · 7 comments
Open

I can't compress and resize my PNG image #76

skykz opened this issue Nov 25, 2020 · 7 comments
Labels
Android Issue on iOS specific devices bug Something isn't working help wanted Extra attention is needed

Comments

@skykz
Copy link

skykz commented Nov 25, 2020

So i did screenshot like this
`RenderRepaintBoundary boundary =
globalKey.currentContext.findRenderObject();

  ui.Image image = await boundary.toImage(
      pixelRatio: 5);

  ByteData byteData =
      await image.toByteData(format: ui.ImageByteFormat.png);
  Uint8List pngBytes = byteData.buffer.asUint8List();

  String dir = (await getApplicationDocumentsDirectory()).path;
  File file = File("$dir/" +
      'AlfaStory' +
      "${DateTime.now().millisecondsSinceEpoch}" +
      ".png");

  await file.writeAsBytes(pngBytes);`

after I want resize this image to target size

`ImageProperties properties =
await FlutterNativeImage.getImageProperties(file.path);
log('IMage properties height: ${properties.height}');
log('IMage properties width: ${properties.width}');

  File compressedFile = await FlutterNativeImage.compressImage(file.path,
      percentage: 0,
      quality: 100,
      targetWidth: 1536,
      targetHeight: 1920);`

Flutter Doctor:
`[√] Flutter (Channel stable, 1.22.0, on Microsoft Windows [Version 10.0.19041.630], locale ru-RU)
• Flutter version 1.22.0 at C:\Users\HP\Desktop\flutter
• Framework revision d408d302e2 (8 weeks ago), 2020-09-29 11:49:17 -0700
• Engine revision 5babba6c4d
• Dart version 2.10.0

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at C:\Users\HP\AppData\Local\Android\sdk
• Platform android-29, build-tools 29.0.2
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
• All Android licenses accepted.

[√] Android Studio (version 3.4)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 37.1.1
• Dart plugin version 183.6270
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[!] IntelliJ IDEA Ultimate Edition (version 2019.2)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2019.2
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
• For information about installing plugins, see
https://flutter.dev/intellij-setup/#installing-the-plugins

[√] VS Code, 64-bit edition (version 1.51.1)
• VS Code at C:\Program Files\Microsoft VS Code
• Flutter extension version 3.16.0

[√] Connected device (1 available)
• Redmi Note 9 Pro (mobile) • 235304a0 • android-arm64 • Android 10 (API 29)`

W/ExifInterface(18131): 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(18131): java.io.IOException: Invalid byte order: ffff8950 W/ExifInterface(18131): at android.media.ExifInterface.readByteOrder(ExifInterface.java:3128) W/ExifInterface(18131): at android.media.ExifInterface.isOrfFormat(ExifInterface.java:2443) W/ExifInterface(18131): at android.media.ExifInterface.getMimeType(ExifInterface.java:2321) W/ExifInterface(18131): at android.media.ExifInterface.loadAttributes(ExifInterface.java:1755) W/ExifInterface(18131): at android.media.ExifInterface.initForFilename(ExifInterface.java:2303) W/ExifInterface(18131): at android.media.ExifInterface.<init>(ExifInterface.java:1386) W/ExifInterface(18131): at com.example.flutternativeimage.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:100) W/ExifInterface(18131): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233) W/ExifInterface(18131): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85) W/ExifInterface(18131): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692) W/ExifInterface(18131): at android.os.MessageQueue.nativePollOnce(Native Method) W/ExifInterface(18131): at android.os.MessageQueue.next(MessageQueue.java:336) W/ExifInterface(18131): at android.os.Looper.loop(Looper.java:181) W/ExifInterface(18131): at android.app.ActivityThread.main(ActivityThread.java:7562) W/ExifInterface(18131): at java.lang.reflect.Method.invoke(Native Method) W/ExifInterface(18131): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) W/ExifInterface(18131): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) [log] IMage properties height: 3098 [log] IMage properties width: 1571 W/ExifInterface(18131): 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.

@IonVillarreal
Copy link

Is there any news ?

@skykz
Copy link
Author

skykz commented Jan 1, 2021

@IonVillarreal right now nothing. I am still waiting =(

@btastic
Copy link
Owner

btastic commented Jan 6, 2021

Sorry for keeping you waiting.

According to the code, the IOException you are getting should be ignored / handled here:

try {
ExifInterface exif = new ExifInterface(fileName);
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
} catch(IOException ex) {
// EXIF could not be read from the file; ignore
}

Which version of flutter_native_image are you using? Can you clear the cache and make sure you're using the latest version?

@skykz
Copy link
Author

skykz commented Jan 7, 2021

Sorry for keeping you waiting.

According to the code, the IOException you are getting should be ignored / handled here:

try {
ExifInterface exif = new ExifInterface(fileName);
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
} catch(IOException ex) {
// EXIF could not be read from the file; ignore
}

Which version of flutter_native_image are you using? Can you clear the cache and make sure you're using the latest version?

Hi, yes everything is okay with cache. I used flutter_native_image: 0.0.5+3. As I said before, plugin crashes in some android smartphones.

@skykz
Copy link
Author

skykz commented Jan 8, 2021

@btastic ? Are u here

@btastic
Copy link
Owner

btastic commented Jan 8, 2021

With the information I currently have, I can not investigate this issue. I checked on my device, and the code is working. I don't have a Redmi Note I could check with. So right now I can't help you myself.

@btastic btastic added Android Issue on iOS specific devices bug Something isn't working help wanted Extra attention is needed labels Apr 7, 2021
@jgoyvaerts
Copy link

This is logged as a warning by Android, as can be seen in the android source code: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/android10-release/media/java/android/media/ExifInterface.java#1801

However, it's only a warning, so it's not the source of your crash. You should look further in your logs where the actual crash happens.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Issue on iOS specific devices bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants