Giter Club home page Giter Club logo

flutter_native_image's People

Contributors

a-leblond avatar acidjazz avatar adithyaxx avatar alphayiuhk avatar aryzhov avatar btastic avatar caijinglong avatar diegoveloper avatar dw2kim avatar greymag avatar hwan-seok avatar lschmierer avatar mazzonem avatar misterjimson avatar netgfx avatar stevenspiel avatar strokine avatar ytakzk avatar yunyu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

flutter_native_image's Issues

Why only downscaling if width/height < 1500

Is there any reason why the downsampling is only applied to images where width or height is > 1500 pixels?
https://github.com/btastic/flutter_native_image/blob/master/ios/Classes/FlutterNativeImagePlugin.m#L51

I have images that are a little smaller (720x1080) that I want to resize. In fact I dont even need to resize at all, but just applying the exif orientation changes as Flutter currently isnt able to display them correctly (flutter/flutter#24455).

compressImage doesn't work if no permission

Hi,

the compressImage function doesn't work in some cases if the user doesn't have the write external storage permission on android. The output image is created in same directory as the original one, so it can be easily fixed by creating the output image in the ExternalCacheDir as a TemporaryFile.

I can pull a hotfix this week, I should have time to do this.

No implementation found...

I'm likely doing something wrong, but I am trying to use your package and keep running into this error for any of the methods: "MissingPluginException(No implementation found for method getImageProperties on channel flutter_native_image)"

This is taking an image from the image picker provided by the Flutter team. I'm assuming the "file.path" requirement is the literal path of the file which I provided but either case, it's still saying that there is no file at this path when I used the iOS simulator.

Code:

Future _imageTest() async {
  ImageProperties properties = await FlutterNativeImage.getImageProperties(widget.imagePath.path.toString());

print(properties.width);
}

A way to manually delete cropped temp files

Hi, first of all, thanks for making this plugin. It has proven to be very useful.

I have the following use case which is giving me a problem:

I have an app where the user constantly takes photos (which are cropped by this plugin) and they get uploaded continuously to a server, and then deleted from the phone. It works fine, except for the fact that every time a photo is taken, a temporary copy is stored in the iOS tmp directory which is not being cleared by the OS, not even when the disk is full.

I'm not sure why exactly the OS is not clearing the tmp folder (checked on various iPhones with different versions), but it could be solved if I could manually delete the temporary copy once the file is already cropped, which I can't because the plugin adds a UUID to the tmp filename.

I could delete the entire tmp folder every once in a while, but that would cause other issues with tmp files not related to this plugin.

Btw, the app works fine on Android :)

getImageProperties should include image rotation

My use case is to store an image in portrait mode with a certain aspect ratio and size. I noticed that on Android, getImageProperties does not work as expected for pictures taken in portrait mode. If the image is in portrait mode, I need to crop it in order to get the desired aspect ratio. For images taken with the built-in camera in portrait mode, getImageProperties returns the size as if the image was in landscape mode. In order to process this case correctly, I need to know the rotation of the image. ImageProperties would be the appropriate place to add the rotation attribute.

When image is picked via imagepicker, the compression is already triggered and the image "jumps" from big to small to big

Any idea, if it's a bug or a mistake in my code (3-week beginner)?

Future getImage() async {
    imageFile = await ImagePicker.pickImage(source: ImageSource.camera);

    if (imageFile != null) {
      setState(() {
        isLoading = true;
      });
      uploadFile();
    }
  }

  Future uploadFile() async {
    //file compression
    File compressedFile = await FlutterNativeImage.compressImage(imageFile.path,
        quality: 50, percentage: 50);
    String fileName = DateTime.now().millisecondsSinceEpoch.toString();
    StorageReference reference = FirebaseStorage.instance.ref().child(fileName);
    StorageUploadTask uploadTask = reference.putFile(compressedFile);
    StorageTaskSnapshot storageTaskSnapshot = await uploadTask.onComplete;
    storageTaskSnapshot.ref.getDownloadURL().then((downloadUrl) {
      imageUrl = downloadUrl;
      setState(() {
        isLoading = false;
        _handleSubmitted(imageUrl: imageUrl);
      });
    }, onError: (err) {
      setState(() {
        isLoading = false;
      });
      Fluttertoast.showToast(msg: 'This file is not an image');
    });
  }

… triggered via

new IconButton(
                icon: new Icon(Icons.photo_camera),
                onPressed: getImage,)

Width or height instead of percentage

Hi !

Would it be possible to add a destination width or height as a parameter instead of a percentage ?
Because i have different images with different sizes and i want all of them to be 900 pixels width.

I know it is possible to do it with the percentage but i need to read the initial width first with this library https://github.com/brendan-duncan/image which is not very optimized for flutter so it takes up to 10-15 seconds just to read the width

Thanks !

Doesn't resize image

I'm testing this out, and it doesn't seem to be resizing images at all, they come out with the same resolution. There's some logs on the console, not sure if related:

my code:

static Future<File> convertToJpeg(File imageFile) async {
    var imageProps = await FlutterNativeImage.getImageProperties(imageFile.path);

    print('convertToJpeg: image width = ${imageProps.width}');
    print('convertToJpeg: image height = ${imageProps.height}');
    if (imageProps.width > maxImageWidth) {
      var start = DateTime.now();
      print('convertToJpeg: resizing image');
      var resizedFile = await FlutterNativeImage.compressImage(imageFile.path, quality: 95, targetWidth: maxImageWidth);
      
      print('convertToJpeg: done resizing took=${DateTime.now().difference(start).inMilliseconds}');

      return resizedFile;
    } else {
      print('convertToJpeg: returning image as is');
      return imageFile;
    }
  }

console output:

I/flutter (23011): convertToJpeg: image width = 480
I/flutter (23011): convertToJpeg: image height = 480
I/flutter (23011): convertToJpeg: resizing image
I/ExifInterface_JNI(23011): Raw image not detected
I/ExifInterface_JNI(23011): Raw image not detected
I/flutter (23011): convertToJpeg: done resizing took=82

thanks!

resize image to 200kb

Dear all,

Is it possible to resize image to exactly 200Kb before upload it to backend?

Thank you in advance.

not work for iOS

Dart Error: Unhandled exception:
MissingPluginException(No implementation found for method compressImage on channel flutter_native_image)
#0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:291:7)
<asynchronous suspension>
#1      FlutterNativeImage.compressImage (package:flutter_native_image/flutter_native_image.dart:16:31)
<asynchronous suspension>
#2      _UserChatSettingsState._compressImage (package:tunnel/tab_page/tab1_children/chatchildren/user_chat_setting.dart:47:50)
<asynchronous suspension>
#3      _UserChatSettingsState._getImage (package:tunnel/tab_page/tab1_children/chatchildren/user_chat_setting.dart:54:20)
<asynchronous suspension>
#4      _UserChatSettingsState.build.<anonymous closure> (package:tunnel/tab_page/tab1_children/chatchildren/user_chat_setting.dart:99:17)
#5      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)

#6      _InkResponseState.build.<anonymous closure> (package:flutter/s<…>

Please update your plugin to work with the latest version of flutter

getting this error while building :

Execution failed for task ':flutter_native_image:verifyReleaseResources'.
> 1 exception was raised by workers:
  com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
  C:\**\build\flutter_native_image\intermediates\res\merged\release\values\values.xml:236: error: resource android:attr/fontVariationSettings not found.
  C:\**\build\flutter_native_image\intermediates\res\merged\release\values\values.xml:237: error: resource android:attr/ttcIndex not found.
  error: failed linking references.

flutter doctor:


[√] Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Version 10.0.18363.535], locale en-US)
    • Flutter version 1.12.13+hotfix.5 at C:\Users\sarin\Documents\flutter
    • Framework revision 27321ebbad (4 days ago), 2019-12-10 18:15:01 -0800
    • Engine revision 2994f7e1e6
    • Dart version 2.7.0

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at C:\Program Files\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • ANDROID_HOME = C:\Program Files\Android\sdk\tools
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
    • All Android licenses accepted.

[√] Android Studio (version 3.5)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 42.0.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[√] VS Code (version 1.41.0)
    • VS Code at C:\Users\sarin\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.7.1

Compressing the same image in different sizes results in file overwrite

Great plugin! Thanks for you work on this.

One thing I'm seeing is that when I compress the same image multiple times (with different compression parameters), the same "_compressed.jpg" ending is added and the previous file is overwritten.

My specific use case is that I generate different sizes and I'd like to upload them asynchronously, but there's no telling which size is which because _compressed.jpg is a moving target.

In the meantime, I can upload the files synchronously, but it's a gotcha that might be worth noting in the README.

Correct way to use cropImage

Can someone explain to me how to use the cropImage function please..

<< FlutterNativeImage.cropImage(file.path, originX, originY, width, height); >>
What means originX, originY, what if with>height... things like that.

Constantly i get this error: java.lang.IllegalArgumentException: x + width must be <= bitmap.width()
Thanks.

IOS crash

Hey I had the problem on android that you fixed last time!.

So the problem now is that I am testing everything on IOS and it seems to crash the app instantly when calling:

File compressedFile = await FlutterNativeImage.compressImage(imageFile.path,
    quality: 60, percentage: 60);

Tried it without this and it worked as expected. I am not getting any error message, it just instantly turns off the app.

Thanks for the awesome plugin!

Failing while building on Bitrise

Hi @btastic , I'm using the Bitrise CI tool to generate iOS artifacts for my application since I don't have a Mac, and here's the log of the error I encounter on getting to the flutter-build stage:

Downloading ios tools... 2.7s
Downloading ios-profile tools... 1.4s
Downloading ios-release tools... 1.1s
Building com.adap.mobile for device (ios-release)...
Automatically signing iOS for device deployment using specified development team in Xcode project: H55G3YSH5P
Running pod install... 6.7s
Running Xcode build...
Xcode build done. 43.5s
Failed to build iOS app
Error output from Xcode build:

** BUILD FAILED **
Xcode's output:

/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/FlutterNativeImagePlugin.m:77:19: warning: unused variable 'fileName' [-Wunused-variable]
NSString *fileName = [[fileArgument lastPathComponent] stringByDeletingPathExtension];
^
1 warning generated.
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Alpha.m:97:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation]
- (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size {
^
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Alpha.m:10:1: note: method 'newBorderMask:size:' declared here
- (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size;
^
1 warning generated.
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Resize.m:151:13: warning: enumeration values 'UIImageOrientationUp' and 'UIImageOrientationUpMirrored' not handled in switch [-Wswitch]
switch (self.imageOrientation) {
^
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Resize.m:151:13: note: add missing switch cases
switch (self.imageOrientation) {
^
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Resize.m:171:13: warning: 4 enumeration values not handled in switch: 'UIImageOrientationUp', 'UIImageOrientationDown', 'UIImageOrientationLeft'... [-Wswitch]
switch (self.imageOrientation) {
^
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Resize.m:171:13: note: add missing switch cases
switch (self.imageOrientation) {
^
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Resize.m:110:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation]
- (UIImage *)resizedImage:(CGSize)newSize
^
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Resize.m:12:1: note: method 'resizedImage:transform:drawTransposed:interpolationQuality:' declared here
- (UIImage *)resizedImage:(CGSize)newSize
^
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Resize.m:148:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation]
- (CGAffineTransform)transformForOrientation:(CGSize)newSize {
^
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Resize.m:16:1: note: method 'transformForOrientation:' declared here
- (CGAffineTransform)transformForOrientation:(CGSize)newSize;
^
4 warnings generated.
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+RoundedCorner.m:60:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation]
- (void)addRoundedRectToPath:(CGRect)rect context:(CGContextRef)context ovalWidth:(CGFloat)ovalWidth ovalHeight:(CGFloat)ovalHeight {
^
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+RoundedCorner.m:11:1: note: method 'addRoundedRectToPath:context:ovalWidth:ovalHeight:' declared here
- (void)addRoundedRectToPath:(CGRect)rect context:(CGContextRef)context ovalWidth:(CGFloat)ovalWidth ovalHeight:(CGFloat)ovalHeight;
^
1 warning generated.
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/FlutterNativeImagePlugin.m:77:19: warning: unused variable 'fileName' [-Wunused-variable]
NSString *fileName = [[fileArgument lastPathComponent] stringByDeletingPathExtension];
^
1 warning generated.
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Alpha.m:97:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation]
- (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size {
^
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Alpha.m:10:1: note: method 'newBorderMask:size:' declared here
- (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size;
^
1 warning generated.
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Resize.m:96:99: warning: enum values with underlying type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead [-Wformat]
[NSException raise:NSInvalidArgumentException format:@"Unsupported content mode: %d", contentMode];
~~ ^~~~~~~~~~~
%ld (long)
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Resize.m:151:13: warning: enumeration values 'UIImageOrientationUp' and 'UIImageOrientationUpMirrored' not handled in switch [-Wswitch]
switch (self.imageOrientation) {
^
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Resize.m:151:13: note: add missing switch cases
switch (self.imageOrientation) {
^
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Resize.m:171:13: warning: 4 enumeration values not handled in switch: 'UIImageOrientationUp', 'UIImageOrientationDown', 'UIImageOrientationLeft'... [-Wswitch]
switch (self.imageOrientation) {
^
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Resize.m:171:13: note: add missing switch cases
switch (self.imageOrientation) {
^
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Resize.m:110:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation]
- (UIImage *)resizedImage:(CGSize)newSize
^
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Resize.m:12:1: note: method 'resizedImage:transform:drawTransposed:interpolationQuality:' declared here
- (UIImage *)resizedImage:(CGSize)newSize
^
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Resize.m:148:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation]
- (CGAffineTransform)transformForOrientation:(CGSize)newSize {
^
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+Resize.m:16:1: note: method 'transformForOrientation:' declared here
- (CGAffineTransform)transformForOrientation:(CGSize)newSize;
^
5 warnings generated.
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+RoundedCorner.m:60:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation]
- (void)addRoundedRectToPath:(CGRect)rect context:(CGContextRef)context ovalWidth:(CGFloat)ovalWidth ovalHeight:(CGFloat)ovalHeight {
^
/Users/vagrant/.pub-cache/git/flutter_native_image-426996b810c8ff3899a6109b65bdab143652e875/ios/Classes/UIImage+RoundedCorner.m:11:1: note: method 'addRoundedRectToPath:context:ovalWidth:ovalHeight:' declared here
- (void)addRoundedRectToPath:(CGRect)rect context:(CGContextRef)context ovalWidth:(CGFloat)ovalWidth ovalHeight:(CGFloat)ovalHeight;
^
1 warning generated.
=== BUILD TARGET Runner OF PROJECT Runner WITH CONFIGURATION Release ===
Code Signing Error: No profiles for 'com.adap.mobile' were found: Xcode couldn't find any iOS App Development provisioning profiles matching 'com.adap.mobile'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild.
The use of Swift 3 @objc inference in Swift 4 mode is deprecated. Please address deprecated @objc inference warnings, test your code with “Use of deprecated Swift 3 @objc inference” logging enabled, and then disable inference by changing the "Swift 3 @objc Inference" build setting to "Default" for the "Runner" target.
The use of Swift 3 @objc inference in Swift 4 mode is deprecated. Please address deprecated @objc inference warnings, test your code with “Use of deprecated Swift 3 @objc inference” logging enabled, and then disable inference by changing the "Swift 3 @objc Inference" build setting to "Default" for the "Runner" target.

compressed image

I have saved PNG image in Application Support folder in iOS. When i try to get the properties of the image it always return width 0 and height 0. Also when i try to save compressed image it save with 0 size even though i have hard coded the width and height.

ImageProperties properties =
                await FlutterNativeImage.getImageProperties(existingImage.path);
File compressedFile = await FlutterNativeImage.compressImage(
                existingImage.path,
                percentage: 100,
                quality: 100,
                targetWidth: 500,
                targetHeight: 300);

Please update for version 0.5.9-pre.17

Running "flutter packages upgrade" in 'project_name'
The current Flutter SDK version is 0.5.9-pre.17.

Because 'project_name' depends on flutter_native_image from git which requires Flutter SDK version >=0.1.0 <=0.5.8, version solving failed.

Unable to add plugin for Flutter Master Channel 0.5.2

Hi
I am using Flutter Master channel 0.5.2
Got error:
Because renalbase depends on flutter_native_image from git which requires Flutter SDK version >=0.1.0 <=0.4.4, version solving failed.

when trying to add in my pub file.

Please help.

Update version on pub

The last update on pub is from June 5th.

Using git dependencies in pubspec should be avoided for consistent results, especially when you don't have control of the repo.

Failed to handle method call

Hi there! I'm facing a issue that was created before #14 , and this issue happened with particular image file.

E/MethodChannel#flutter_native_image( 5197): java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
E/MethodChannel#flutter_native_image( 5197): 	at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:734)
E/MethodChannel#flutter_native_image( 5197): 	at com.example.flutternativeimage.FlutterNativeImagePlugin.onMethodCall(FlutterNativeImagePlugin.java:64)
E/MethodChannel#flutter_native_image( 5197): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
E/MethodChannel#flutter_native_image( 5197): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
E/MethodChannel#flutter_native_image( 5197): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:656)
E/MethodChannel#flutter_native_image( 5197): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#flutter_native_image( 5197): 	at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#flutter_native_image( 5197): 	at android.os.Looper.loop(Looper.java:160)
E/MethodChannel#flutter_native_image( 5197): 	at android.app.ActivityThread.main(ActivityThread.java:6669)
E/MethodChannel#flutter_native_image( 5197): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter_native_image( 5197): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#flutter_native_image( 5197): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
I/flutter ( 5197): Crop image faild: PlatformException(error, Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference, null)

This happened when I was trying to compress image.

final path = (await getApplicationDocumentsDirectory()).path;
File file = File("$path/_temp_avatar.jpg");
file.writeAsBytes(await cropImage(state: _editorKey.currentState));
File compressedFile = await FlutterNativeImage.compressImage(
  file.path,
  quality: 100,
  targetWidth: 640,
  targetHeight: 640,
);

Hope you can help me with this, I'm referencing the latest commit.

Preserve exif information after crompessed file

I have a file taken from ImagePicker.pickImage
that I want to resize and then I want to know his orientation
because I want to it be always in portrait orientation for write image in pdf.

On Android I noticed after compressed file with flutter_native_image the exif information is lost.
if you use brendan-duncan/image for decode image you'll notice that orientation is null.

File compressedFile = await FlutterNativeImage.compressImage(dat[i].path, quality: 80,
      targetWidth: 600,
      targetHeight: (properties.height * 600 / properties.width).round());
List<int> byte = compressedFile.readAsBytesSync();
Im.Image img = Im.decodeImage(byte);
int orientation = img.exif.orientation; # is null

getImageProperties should include date taken

It would be nice to get also image date/time information in ImageProperties (specifically the date image was taken). This is needed e.g. for displaying images in date/time order.

Xcode 10 Swift 4.2 not compile

Need to update to swift 4.2, The BSImagePicker have been upgrade, so no update build failed.

error: 'UIApplicationLaunchOptionsKey' has been renamed to 'UIApplication.LaunchOptionsKey'

UIKit.UIApplicationLaunchOptionsKey:2:18: note: 'UIApplicationLaunchOptionsKey' was obsoleted in Swift 4.2

flutter run ->

Xcode's output:

/Users/frank/.pub-cache/git/flutter_native_image-21fc96be5a4f41ecab883df52872505fec44576e/ios/Classes/FlutterNativ
eImagePlugin.m:93:19: warning: unused variable 'fileName' [-Wunused-variable]
NSString *fileName = [[fileArgument lastPathComponent] stringByDeletingPathExtension];
^
1 warning generated.
/Users/frank/.pub-cache/git/flutter_native_image-21fc96be5a4f41ecab883df52872505fec44576e/ios/Classes/UIImage+Alph
a.m:97:1: warning: category is implementing a method which will also be implemented by its primary class
[-Wobjc-protocol-method-implementation]
- (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size {
^
/Users/frank/.pub-cache/git/flutter_native_image-21fc96be5a4f41ecab883df52872505fec44576e/ios/Classes/UIImage+Alph
a.m:10:1: note: method 'newBorderMask:size:' declared here
- (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size;
^
1 warning generated.
/Users/frank/.pub-cache/git/flutter_native_image-21fc96be5a4f41ecab883df52872505fec44576e/ios/Classes/UIImage+Resi
ze.m:96:99: warning: enum values with underlying type 'NSInteger' should not be used as format arguments; add an
explicit cast to 'long' instead [-Wformat]
[NSException raise:NSInvalidArgumentException format:@"Unsupported content mode: %d", contentMode];
~~ ^~~~~~~~~~~
%ld (long)
/Users/frank/.pub-cache/git/flutter_native_image-21fc96be5a4f41ecab883df52872505fec44576e/ios/Classes/UIImage+Resi
ze.m:151:13: warning: enumeration values 'UIImageOrientationUp' and 'UIImageOrientationUpMirrored' not handled in
switch [-Wswitch]
switch (self.imageOrientation) {
^
/Users/frank/.pub-cache/git/flutter_native_image-21fc96be5a4f41ecab883df52872505fec44576e/ios/Classes/UIImage+Resi
ze.m:151:13: note: add missing switch cases
switch (self.imageOrientation) {
^
/Users/frank/.pub-cache/git/flutter_native_image-21fc96be5a4f41ecab883df52872505fec44576e/ios/Classes/UIImage+Resi
ze.m:171:13: warning: 4 enumeration values not handled in switch: 'UIImageOrientationUp',
'UIImageOrientationDown', 'UIImageOrientationLeft'... [-Wswitch]
switch (self.imageOrientation) {
^
/Users/frank/.pub-cache/git/flutter_native_image-21fc96be5a4f41ecab883df52872505fec44576e/ios/Classes/UIImage+Resi
ze.m:171:13: note: add missing switch cases
switch (self.imageOrientation) {
^
/Users/frank/.pub-cache/git/flutter_native_image-21fc96be5a4f41ecab883df52872505fec44576e/ios/Classes/UIImage+Resi
ze.m:110:1: warning: category is implementing a method which will also be implemented by its primary class
[-Wobjc-protocol-method-implementation]
- (UIImage *)resizedImage:(CGSize)newSize
^
/Users/frank/.pub-cache/git/flutter_native_image-21fc96be5a4f41ecab883df52872505fec44576e/ios/Classes/UIImage+Resi
ze.m:12:1: note: method 'resizedImage:transform:drawTransposed:interpolationQuality:' declared here
- (UIImage *)resizedImage:(CGSize)newSize
^
/Users/frank/.pub-cache/git/flutter_native_image-21fc96be5a4f41ecab883df52872505fec44576e/ios/Classes/UIImage+Resi
ze.m:148:1: warning: category is implementing a method which will also be implemented by its primary class
[-Wobjc-protocol-method-implementation]
- (CGAffineTransform)transformForOrientation:(CGSize)newSize {
^
/Users/frank/.pub-cache/git/flutter_native_image-21fc96be5a4f41ecab883df52872505fec44576e/ios/Classes/UIImage+Resi
ze.m:16:1: note: method 'transformForOrientation:' declared here
- (CGAffineTransform)transformForOrientation:(CGSize)newSize;
^
5 warnings generated.
/Users/frank/.pub-cache/git/flutter_native_image-21fc96be5a4f41ecab883df52872505fec44576e/ios/Classes/UIImage+Roun
dedCorner.m:60:1: warning: category is implementing a method which will also be implemented by its primary class
[-Wobjc-protocol-method-implementation]
- (void)addRoundedRectToPath:(CGRect)rect context:(CGContextRef)context ovalWidth:(CGFloat)ovalWidth
ovalHeight:(CGFloat)ovalHeight {
^
/Users/frank/.pub-cache/git/flutter_native_image-21fc96be5a4f41ecab883df52872505fec44576e/ios/Classes/UIImage+Roun
dedCorner.m:11:1: note: method 'addRoundedRectToPath:context:ovalWidth:ovalHeight:' declared here
- (void)addRoundedRectToPath:(CGRect)rect context:(CGContextRef)context ovalWidth:(CGFloat)ovalWidth
ovalHeight:(CGFloat)ovalHeight;
^
1 warning generated.
=== BUILD TARGET Runner OF PROJECT Runner WITH CONFIGURATION Debug ===
The use of Swift 3 @objc inference in Swift 4 mode is deprecated. Please address deprecated @objc inference
warnings, test your code with “Use of deprecated Swift 3 @objc inference” logging enabled, and then disable
inference by changing the "Swift 3 @objc Inference" build setting to "Default" for the "Runner" target.
=== BUILD TARGET Runner OF PROJECT Runner WITH CONFIGURATION Debug ===
/web/native/aijia/ios/Runner/AppDelegate.swift:8:51: error: 'UIApplicationLaunchOptionsKey' has been renamed to
'UIApplication.LaunchOptionsKey'
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
UIApplication.LaunchOptionsKey
UIKit.UIApplicationLaunchOptionsKey:2:18: note: 'UIApplicationLaunchOptionsKey' was obsoleted in Swift 4.2
public typealias UIApplicationLaunchOptionsKey = UIApplication.LaunchOptionsKey
^

Could not build the application for the simulator.
Error launching application on iPhone XR.

Warnings when building

warning: unused variable 'fileName' [-Wunused-variable]
NSString *fileName = [[fileArgument lastPathComponent] stringByDeletingPathExtension];

warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation]
- (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size {

method 'newBorderMask:size:' declared here
- (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size;

warning: enumeration values 'UIImageOrientationUp' and 'UIImageOrientationUpMirrored' not handled in switch [-Wswitch]
switch (self.imageOrientation) {
^
/Users/peterlum/dev/flutter/.pub-cache/git/flutter_native_image-570cafee663b360c27be9a002d15bda020332f5b/ios/Classes/UIImage+Resize.m:151:13: note: add missing switch cases
switch (self.imageOrientation) {
^
/Users/peterlum/dev/flutter/.pub-cache/git/flutter_native_image-570cafee663b360c27be9a002d15bda020332f5b/ios/Classes/UIImage+Resize.m:171:13: warning: 4 enumeration values not handled in switch: 'UIImageOrientationUp', 'UIImageOrientationDown', 'UIImageOrientationLeft'... [-Wswitch]
switch (self.imageOrientation) {
^
/Users/peterlum/dev/flutter/.pub-cache/git/flutter_native_image-570cafee663b360c27be9a002d15bda020332f5b/ios/Classes/UIImage+Resize.m:171:13: note: add missing switch cases
switch (self.imageOrientation) {
^
/Users/peterlum/dev/flutter/.pub-cache/git/flutter_native_image-570cafee663b360c27be9a002d15bda020332f5b/ios/Classes/UIImage+Resize.m:110:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation]
- (UIImage *)resizedImage:(CGSize)newSize
^
/Users/peterlum/dev/flutter/.pub-cache/git/flutter_native_image-570cafee663b360c27be9a002d15bda020332f5b/ios/Classes/UIImage+Resize.m:12:1: note: method 'resizedImage:transform:drawTransposed:interpolationQuality:' declared here
- (UIImage *)resizedImage:(CGSize)newSize
^
/Users/peterlum/dev/flutter/.pub-cache/git/flutter_native_image-570cafee663b360c27be9a002d15bda020332f5b/ios/Classes/UIImage+Resize.m:148:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation]
- (CGAffineTransform)transformForOrientation:(CGSize)newSize {
^
/Users/peterlum/dev/flutter/.pub-cache/git/flutter_native_image-570cafee663b360c27be9a002d15bda020332f5b/ios/Classes/UIImage+Resize.m:16:1: note: method 'transformForOrientation:' declared here
- (CGAffineTransform)transformForOrientation:(CGSize)newSize;
^
4 warnings generated.
/Users/peterlum/dev/flutter/.pub-cache/git/flutter_native_image-570cafee663b360c27be9a002d15bda020332f5b/ios/Classes/UIImage+RoundedCorner.m:60:1: warning: category isimplementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation]
- (void)addRoundedRectToPath:(CGRect)rect context:(CGContextRef)context ovalWidth:(CGFloat)ovalWidth ovalHeight:(CGFloat)ovalHeight {
^
/Users/peterlum/dev/flutter/.pub-cache/git/flutter_native_image-570cafee663b360c27be9a002d15bda020332f5b/ios/Classes/UIImage+RoundedCorner.m:11:1: note: method 'addRoundedRectToPath:context:ovalWidth:ovalHeight:' declared here
- (void)addRoundedRectToPath:(CGRect)rect context:(CGContextRef)context ovalWidth:(CGFloat)ovalWidth ovalHeight:(CGFloat)ovalHeight;
^
1 warning generated.
/Users/peterlum/dev/flutter/.pub-cache/git/flutter_native_image-570cafee663b360c27be9a002d15bda020332f5b/ios/Classes/FlutterNativeImagePlugin.m:93:19: warning: unused variable 'fileName' [-Wunused-variable]
NSString *fileName = [[fileArgument lastPathComponent] stringByDeletingPathExtension];
^
1 warning generated.
/Users/peterlum/dev/flutter/.pub-cache/git/flutter_native_image-570cafee663b360c27be9a002d15bda020332f5b/ios/Classes/UIImage+Alpha.m:97:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation]
- (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size {
^
/Users/peterlum/dev/flutter/.pub-cache/git/flutter_native_image-570cafee663b360c27be9a002d15bda020332f5b/ios/Classes/UIImage+Alpha.m:10:1: note: method 'newBorderMask:size:' declared here
- (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size;
^
1 warning generated.
/Users/peterlum/dev/flutter/.pub-cache/git/flutter_native_image-570cafee663b360c27be9a002d15bda020332f5b/ios/Classes/UIImage+Resize.m:96:99: warning: enum values with underlying type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead [-Wformat]
[NSException raise:NSInvalidArgumentException format:@"Unsupported content mode: %d", contentMode];
~~ ^~~~~~~~~~~
%ld (long)
/Users/peterlum/dev/flutter/.pub-cache/git/flutter_native_image-570cafee663b360c27be9a002d15bda020332f5b/ios/Classes/UIImage+Resize.m:151:13: warning: enumeration values 'UIImageOrientationUp' and 'UIImageOrientationUpMirrored' not handled in switch [-Wswitch]
switch (self.imageOrientation) {
^
/Users/peterlum/dev/flutter/.pub-cache/git/flutter_native_image-570cafee663b360c27be9a002d15bda020332f5b/ios/Classes/UIImage+Resize.m:151:13: note: add missing switch cases
switch (self.imageOrientation) {
^
/Classes/UIImage+Resize.m:171:13: warning: 4 enumeration values not handled in switch: 'UIImageOrientationUp', 'UIImageOrientationDown', 'UIImageOrientationLeft'... [-Wswitch]
switch (self.imageOrientation) {
^
Classes/UIImage+Resize.m:171:13: note: add missing switch cases
switch (self.imageOrientation) {
^
Classes/UIImage+Resize.m:110:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation]
- (UIImage *)resizedImage:(CGSize)newSize
^
Classes/UIImage+Resize.m:12:1: note: method 'resizedImage:transform:drawTransposed:interpolationQuality:' declared here
- (UIImage *)resizedImage:(CGSize)newSize

And many, many others ...

Does not work on iOS

error: Exception: error: native function 'Window_sendPlatformMessage' (4 arguments) cannot be found
flutter: =====>#0 Window.sendPlatformMessage (dart:ui/window.dart:811:9)
#1 BinaryMessages._sendPlatformMessage (package:flutter/src/services/platform_messages.dart:39:15)
#2 BinaryMessages.send (package:flutter/src/services/platform_messages.dart:87:12)
#3 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:286:49)

#4 FlutterNativeImage.getImageProperties (package:flutter_native_image/flutter_native_image.dart:45:33)

feature: grayscaling

Would you accept a PR that adds the possibility to grayscale the image (after scaling) ?

getExternalCacheDir() called on null when added to native android app

I am adding a flutter module using flutter_native_image as a dependency to a native android app. I get the error in the title when the android app is run. It seems like activity is always null which causes this issue.

I suspect this is something to do with v2 embedding and a migration of this plugin could possibly fix the issue. I'll open a PR if I manage to fix it.

Crop doesn't work on iOS

I'm trying to square crop an image using the following code:

Future<String> _resizePhoto(String filePath) async {
    try {
      ImageProperties properties =
          await FlutterNativeImage.getImageProperties(filePath);

      print("Width: ${properties.width}, Height: ${properties.height}");

      int width = properties.width;
      var offset = (properties.height - properties.width) / 2;

      print("Offset = ${offset.round()}");

      File croppedFile = await FlutterNativeImage.cropImage(
          filePath, 0, offset.round(), width, width);

      // Check it worked
      properties =
      await FlutterNativeImage.getImageProperties(croppedFile.path);
      print("Width: ${properties.width}, Height: ${properties.height}");

      return croppedFile.path;
    } catch (e) {
      print(e);
    }
  }

Instead of getting a square cropped image, the image is shown sideways with some of the top-left of the image shown. The printed output suggests things have gone wrong:

flutter: Width: 720, Height: 1280
flutter: Offset = 280               // This seems correct. Cutting 280 will square the image
flutter: Width: 720, Height: 440    // This correlates to what I see in the final image, 
                                    // but I expected w720 x h720

Am I using this function correctly?

FYI - the source of my image is a camera capture, taken using the camera package.

[Bug] Cannot get image properties if file name contain white space on iOS

Steps to reproduce:

  • Generate a file with path containing white space such as .../26-Jun-2020 12:24:45.png
  • Get image properties
    ImageProperties properties = await FlutterNativeImage.getImageProperties(filePath);

Expected result:

  • Be able to get height and width of image

Actual result:

  • properties.height = 0 & properties.width = 0

It happens on iOS only, work well on Android. It can workaround by remove all white space, but I just report here so others will be noticed.

Crashing on iOS real devices

Hello, I've tested this package on both iOS and Android real devices. While it is slowly working on Android, it does not work on iOS at all. It always crashes on iOS real devices and same for simulators.

compress screenshot dosn't work on iOS

iPhone7
iOS 13
UIImage+Resize.m
line 119
CGBitmapContextCreate(NULL,
newRect.size.width,
newRect.size.height,
CGImageGetBitsPerComponent(imageRef),
0,
CGImageGetColorSpace(imageRef),
CGImageGetBitmapInfo(imageRef));

CGBitmapContextCreate: unsupported parameter combination:
16 bits/component; integer;
64 bits/pixel;
RGB color space model; kCGImageAlphaLast;
kCGImageByteOrder16Little byte order;
4800 bytes/row.
Valid parameters for RGB color space model are:
16 bits per pixel, 5 bits per component, kCGImageAlphaNoneSkipFirst
32 bits per pixel, 8 bits per component, kCGImageAlphaNoneSkipFirst
32 bits per pixel, 8 bits per component, kCGImageAlphaNoneSkipLast
32 bits per pixel, 8 bits per component, kCGImageAlphaPremultipliedFirst
32 bits per pixel, 8 bits per component, kCGImageAlphaPremultipliedLast
32 bits per pixel, 10 bits per component, kCGImageAlphaNone|kCGImagePixelFormatRGBCIF10
64 bits per pixel, 16 bits per component, kCGImageAlphaPremultipliedLast
64 bits per pixel, 16 bits per component, kCGImageAlphaNoneSkipLast
64 bits per pixel, 16 bits per component, kCGImageAlphaPremultipliedLast|kCGBitmapFloatComponents
64 bits per pixel, 16 bits per component, kCGImageAlphaNoneSkipLast|kCGBitmapFloatComponents
128 bits per pixel, 32 bits per component, kCGImageAlphaPremultipliedLast|kCGBitmapFloatComponents
128 bits per pixel, 32 bits per component, kCGImageAlphaNoneSkipLast|kCGBitmapFloatComponents
See Quartz 2D Programming Guide (available online) for more information.
2019-12-07 14:20:30.212171+0800 Runner[723:155855] [Unknown process name] CGContextConcatCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2019-12-07 14:20:30.212577+0800 Runner[723:155855] [Unknown process name] CGContextSetInterpolationQuality: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2019-12-07 14:20:30.212873+0800 Runner[723:155855] [Unknown process name] CGContextDrawImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2019-12-07 14:20:30.213913+0800 Runner[723:155855] [Unknown process name] CGBitmapContextCreateImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

Stop reading file, tag not defined...

Not so much of an issue, but I was getting a lot of system messages such as failed to close resource, tag not defined, stop reading file-offset may cause infinite loop...

I cleared them all by:
changing import to the androidx ExifInterface.
changing the dependency to: implementation 'androidx.exifinterface:exifinterface:1.1.0-rc01' in the build gradle.
Changed tag 'IsoSpeedRatings' to 'PhotographicSensitivity'.
Added calls to Reset(), Close() for the ByteArrayOutputStream bos object.

None of these were causing errors or crashing the app, so this is more of an FYI rather than an issue.

Plugin is not working any more for both iOS and Android

The package was working perfectly fine, but now I get the following errors:

iOS
Xcode's output: ↳ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Alpha 2.m:97:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation] - (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size { ^ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Alpha 2.m:10:1: note: method 'newBorderMask:size:' declared here - (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size; ^ 1 warning generated. /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/FlutterNativeImagePlugin.m:76:19: warning: unused variable 'fileName' [-Wunused-variable] NSString *fileName = [[fileArgument lastPathComponent] stringByDeletingPathExtension]; ^ 1 warning generated. /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/FlutterNativeImagePlugin 2.m:76:19: warning: unused variable 'fileName' [-Wunused-variable] NSString *fileName = [[fileArgument lastPathComponent] stringByDeletingPathExtension]; ^ 1 warning generated. /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Alpha.m:97:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation] - (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size { ^ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Alpha.m:10:1: note: method 'newBorderMask:size:' declared here - (CGImageRef)newBorderMask:(NSUInteger)borderSize size:(CGSize)size; ^ 1 warning generated. /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Resize.m:96:99: warning: enum values with underlying type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead [-Wformat] [NSException raise:NSInvalidArgumentException format:@"Unsupported content mode: %d", contentMode]; ~~ ^~~~~~~~~~~ %ld (long) /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Resize.m:151:13: warning: enumeration values 'UIImageOrientationUp' and 'UIImageOrientationUpMirrored' not handled in switch [-Wswitch] switch (self.imageOrientation) { ^ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Resize.m:151:13: note: add missing switch cases switch (self.imageOrientation) { ^ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Resize.m:171:13: warning: 4 enumeration values not handled in switch: 'UIImageOrientationUp', 'UIImageOrientationDown', 'UIImageOrientationLeft'... [-Wswitch] switch (self.imageOrientation) { ^ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Resize.m:171:13: note: add missing switch cases switch (self.imageOrientation) { ^ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Resize.m:110:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation] - (UIImage *)resizedImage:(CGSize)newSize ^ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Resize.m:12:1: note: method 'resizedImage:transform:drawTransposed:interpolationQuality:' declared here - (UIImage *)resizedImage:(CGSize)newSize ^ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Resize.m:148:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation] - (CGAffineTransform)transformForOrientation:(CGSize)newSize { ^ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Resize.m:16:1: note: method 'transformForOrientation:' declared here - (CGAffineTransform)transformForOrientation:(CGSize)newSize; ^ 5 warnings generated. /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+RoundedCorner 2.m:60:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation] - (void)addRoundedRectToPath:(CGRect)rect context:(CGContextRef)context ovalWidth:(CGFloat)ovalWidth ovalHeight:(CGFloat)ovalHeight { ^ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+RoundedCorner 2.m:11:1: note: method 'addRoundedRectToPath:context:ovalWidth:ovalHeight:' declared here - (void)addRoundedRectToPath:(CGRect)rect context:(CGContextRef)context ovalWidth:(CGFloat)ovalWidth ovalHeight:(CGFloat)ovalHeight; ^ 1 warning generated. /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Resize 2.m:96:99: warning: enum values with underlying type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead [-Wformat] [NSException raise:NSInvalidArgumentException format:@"Unsupported content mode: %d", contentMode]; ~~ ^~~~~~~~~~~ %ld (long) /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Resize 2.m:151:13: warning: enumeration values 'UIImageOrientationUp' and 'UIImageOrientationUpMirrored' not handled in switch [-Wswitch] switch (self.imageOrientation) { ^ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Resize 2.m:151:13: note: add missing switch cases switch (self.imageOrientation) { ^ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Resize 2.m:171:13: warning: 4 enumeration values not handled in switch: 'UIImageOrientationUp', 'UIImageOrientationDown', 'UIImageOrientationLeft'... [-Wswitch] switch (self.imageOrientation) { ^ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Resize 2.m:171:13: note: add missing switch cases switch (self.imageOrientation) { ^ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Resize 2.m:110:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation] - (UIImage *)resizedImage:(CGSize)newSize ^ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Resize 2.m:12:1: note: method 'resizedImage:transform:drawTransposed:interpolationQuality:' declared here - (UIImage *)resizedImage:(CGSize)newSize ^ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Resize 2.m:148:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation] - (CGAffineTransform)transformForOrientation:(CGSize)newSize { ^ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+Resize 2.m:16:1: note: method 'transformForOrientation:' declared here - (CGAffineTransform)transformForOrientation:(CGSize)newSize; ^ 5 warnings generated. /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+RoundedCorner.m:60:1: warning: category is implementing a method which will also be implemented by its primary class [-Wobjc-protocol-method-implementation] - (void)addRoundedRectToPath:(CGRect)rect context:(CGContextRef)context ovalWidth:(CGFloat)ovalWidth ovalHeight:(CGFloat)ovalHeight { ^ /Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/ios/Classes/UIImage+RoundedCorner.m:11:1: note: method 'addRoundedRectToPath:context:ovalWidth:ovalHeight:' declared here - (void)addRoundedRectToPath:(CGRect)rect context:(CGContextRef)context ovalWidth:(CGFloat)ovalWidth ovalHeight:(CGFloat)ovalHeight; ^ 1 warning generated. duplicate symbol _OBJC_CLASS_$_FlutterNativeImagePlugin in: /Users/matthiaswolff/Library/Developer/Xcode/DerivedData/Runner-gsxvlimcvnntndaqztttqmcyyeqw/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/flutter_native_image.build/Objects-normal/arm64/FlutterNativeImagePlugin 2.o /Users/matthiaswolff/Library/Developer/Xcode/DerivedData/Runner-gsxvlimcvnntndaqztttqmcyyeqw/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/flutter_native_image.build/Objects-normal/arm64/FlutterNativeImagePlugin.o duplicate symbol _OBJC_METACLASS_$_FlutterNativeImagePlugin in: /Users/matthiaswolff/Library/Developer/Xcode/DerivedData/Runner-gsxvlimcvnntndaqztttqmcyyeqw/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/flutter_native_image.build/Objects-normal/arm64/FlutterNativeImagePlugin 2.o /Users/matthiaswolff/Library/Developer/Xcode/DerivedData/Runner-gsxvlimcvnntndaqztttqmcyyeqw/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/flutter_native_image.build/Objects-normal/arm64/FlutterNativeImagePlugin.o ld: 2 duplicate symbols for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Android:
`/Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/android/src/main/java/com/example/flutternativeimage/FlutterNativeImagePlugin 2.java:32: error: class FlutterNativeImagePlugin is public, should be declared in a file named FlutterNativeImagePlugin.java
public class FlutterNativeImagePlugin implements MethodCallHandler {
^
/Users/matthiaswolff/Desktop/flutter/.pub-cache/git/flutter_native_image-691a48cb495aab3b7c4c3caf41f3431ed26abc9c/android/src/main/java/com/example/flutternativeimage/FlutterNativeImagePlugin.java:32: error: duplicate class: com.example.flutternativeimage.FlutterNativeImagePlugin
public class FlutterNativeImagePlugin implements MethodCallHandler {
^
2 errors

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':flutter_native_image:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.`

Error when calling compressImage

Hey!

Tried your lib for compressing my image on android but when I call the compressImage method like this:

File compressedFile = await FlutterNativeImage.compressImage(imageFile.path,
    quality: 60, percentage: 60);

it results in this error:

E/MethodChannel#flutter_native_image(10518): Failed to handle method call
E/MethodChannel#flutter_native_image(10518): java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
E/MethodChannel#flutter_native_image(10518): at com.example.flutternativeimage.FlutterNativeImagePlugin.onMethodCall(FlutterNativeImagePlugin.java:51)
E/MethodChannel#flutter_native_image(10518): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:191)
E/MethodChannel#flutter_native_image(10518): at io.flutter.view.FlutterNativeView.handlePlatformMessage(FlutterNativeView.java:152)
E/MethodChannel#flutter_native_image(10518): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#flutter_native_image(10518): at android.os.MessageQueue.next(MessageQueue.java:325)
E/MethodChannel#flutter_native_image(10518): at android.os.Looper.loop(Looper.java:142)
E/MethodChannel#flutter_native_image(10518): at android.app.ActivityThread.main(ActivityThread.java:6798)
E/MethodChannel#flutter_native_image(10518): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter_native_image(10518): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
E/MethodChannel#flutter_native_image(10518): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
E/flutter (10518): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (10518): PlatformException(error, Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference, null)
E/flutter (10518): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:547:7)
E/flutter (10518): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:279:18)
E/flutter (10518):
E/flutter (10518): #2 FlutterNativeImage.compressImage (package:flutter_native_image/flutter_native_image.dart:15:31)
E/flutter (10518):
E/flutter (10518): #3 _CreatePlantState._addPlantToUser (package:planti/Plant/CreatePlant.dart:180:52)
E/flutter (10518):
E/flutter (10518): #4 _CreatePlantState.checkSubscription (package:planti/Plant/CreatePlant.dart:217:13)
E/flutter (10518):
E/flutter (10518): #5 _CreatePlantState.build.. (package:planti/Plant/CreatePlant.dart:64:38)
E/flutter (10518): #6 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:494:14)
E/flutter (10518): #7 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:549:30)
E/flutter (10518): #8 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
E/flutter (10518): #9 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:161:9)
E/flutter (10518): #10 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:94:7)
E/flutter (10518): #11 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
E/flutter (10518): #12 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
E/flutter (10518): #13 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
E/flutter (10518): #14 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
E/flutter (10518): #15 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
E/flutter (10518): #16 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
E/flutter (10518): #17 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
E/flutter (10518): #18 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
E/flutter (10518): #19 _invoke1 (dart:ui/hooks.dart:134:13)
E/flutter (10518): #20 _dispatchPointerDataPacket (dart:ui/hooks.dart:91:5)

compressImage with specific size shows inverted results

My code

File _newFile;

if (properties.width > 3840 && properties.height > 2160) {
      _newFile = await FlutterNativeImage.compressImage(item.path, quality: 100, targetWidth: 3840, targetHeight: 2160);
}

The output image shows height 3840 and width 2160.

Crop error in the landscape mode

I want to take photo, compress this photo and crop middle square from this image. When I use the portrait mode, I don't have any mistakes. But, if I use the landscape mode I get that mistake:

[VERBOSE-2:shell.cc(184)] Dart Error: Unhandled exception:
PlatformException(bounds_error, Bounds are outside of the dimensions of the source image, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:551:7)
#1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:292:18)
<asynchronous suspension>
#2      FlutterNativeImage.cropImage (package:flutter_native_image/flutter_native_image.dart:52:31)
<asynchronous suspension>
#3      takePhoto (package:flu_kids_client/client/client_kid.dart:214:47)
<asynchronous suspension>
#4      _contactChild.<anonymous closure> (package:flu_kids_client/client/client_kid.dart:82:19)
<asynchronous suspension>
#5      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)
#6      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:562:30)
#7      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
#8      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
#9      TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:204:7)
#10     GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
#11     _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:184:20)
#12     _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:158:22)
#13     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:138:7)
#14     _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7)
#15     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7)
#16     _invoke1 (dart:ui/hooks.dart:168:13)
#17     _dispatchPointerDataPacket (dart:ui/hooks.dart:122:5)

There is my code:

takePhoto() async {
  // Делаем снимок камерой
  File largeImageFile = await ImagePicker.pickImage(source: ImageSource.camera);

  // Получаем ширину и высоту оригинала
  ImageProperties properties =
      await FlutterNativeImage.getImageProperties(largeImageFile.path);

  // Смотрим ориентацию экрана. От нее зависит, по какой стороне будем резать картинку.
  int size = 100;
  int quality = 80;
  int compressedWidth;
  int compressedHeight;
  if (properties.width >= properties.height) {
    compressedWidth = (properties.width * size / properties.height).round();
    compressedHeight = size;
  } else {
    compressedWidth = size;
    compressedHeight = (properties.height * size / properties.width).round();
  }
  File compressedFile = await FlutterNativeImage.compressImage(largeImageFile.path,
      quality: quality,
      targetWidth: size,
      targetHeight: (properties.height * size / properties.width).round());

  // Вырезаем квадратную середину изображения
  int originX = 0;
  int originY = 0;
  if (properties.width >= properties.height) {
    originX = ((compressedWidth - size) / 2).round();
  } else {
    originY = ((compressedHeight - size) / 2).round();
  }
  File croppedFile = await FlutterNativeImage.cropImage(compressedFile.path, originX, originY, size, size);

  Store.pageState.setState(() {
    _smallImageFile = croppedFile;
  });
}

Where is a mistake?

Rotating image

Is there a possibility to add image rotation feature? So it can be 90, 180, 270 degrees rotated.
Not quite familiar with image resizing logic so asking as feature request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.