brendan-duncan / image

Dart Image Library for opening, manipulating, and saving various different image file formats.
MIT License
1.17k stars 266 forks source link

in Flutter save an image to local album #79

Closed lucasjinreal closed 2 years ago

lucasjinreal commented 6 years ago

I know this not a issue about image, but I want save a image into local album in flutter but CAN NOT found any solution about this. Here is what I got for now:

Future<File> saveImage(String url) async {
    final file = await getImageFromNetwork(url);
    print('save $url, got file: $file');

    //retrieve local path for device
    var path = await _localPath;
    ImageIO.Image image = ImageIO.decodeImage(file.readAsBytesSync());
    print(image);

    return new File('$path/${DateTime.now().toUtc().toIso8601String()}.png')
      ..writeAsBytesSync(ImageIO.encodePng(image));
  }

The image write to a new file, but this not saved as album and can not find the iOS or Android system album app. Anyone can give a hint how to achieve this?

brendan-duncan commented 6 years ago

Unfortunately I haven’t done anything with Flutter yet and don’t know the answer. According to https://stackoverflow.com/questions/49987707/how-to-save-an-image-to-the-photo-gallery-using-flutter it looks like you might need to write a native extension to do it.

yabinma commented 6 years ago

Same request here.

For now, in my Flutter APP, I have wrote the native code for Android channel to refresh Mediastore, so that the image file can be found in Album. But it is quite inconvenient to write native code on this. This is a common requirement.

I would like to improve it so that 'Intent.ACTION_MEDIA_SCANNER_SCAN_FILE' can be called in Flutter code easily. It is quite small code and it is not worth to create an individual plugin. So that I searched the current plugins library and would like to add the function there. Unfortunately, so far I did not find a proper plugin to add it.

I am not sure if it is ok to add the function here. Means, adding a method like, Image.refresh(file.path); And then in the plugin code(might be Java), to add like,

Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri uri = Uri.fromFile(new File(<filePath>));
intent.setData(uri);
sendBroadcast(intent);

Where <filePath> is the image file path and provided in Image.refresh(file.path);.

Thought?

Thank you!

Max Ma

brendan-duncan commented 6 years ago

If you're asking if I can add the Java code to the Image package, I don't think I'll be able to do that. I haven't and don't have any plans to do any Flutter development any time soon, and won't be able to test, support, or maintain any native solutions. If you wanted to add it to the package, and can verify it will be isolated to Android platform and not affect any other platform, then I'll certainly consider the pull request to add it in.

lucasjinreal commented 5 years ago

@maxatcn @brendan-duncan There is a library can do this now from community. It can downloads image from url and save image to album

nanunh commented 5 years ago

@maxatcn @brendan-duncan There is a library can do this now from community. It can downloads image from url and save image to album

@jinfagang Please provide the link and usage instructions with IOS and Android. thx!

lucasjinreal commented 5 years ago

@nanunh I think it is here https://github.com/ko2ic/image_downloader . Meanwhile if you tested it success, pls let me know, and I can close this issue. BTW, this packages seems has some problem on iOS, if you have an iOS devices or mac, you can test iOS too.

sharmaakhil100 commented 5 years ago

https://pub.dev/packages/image_gallery_saver this one works with this module. This package has successfully worked on both iPhone (real device) and Android (emulator) for me. let me know if this solves this issue for you. Example. (use this code inside an async future function): var x = encodeJpg(image1); // image1 is of type Image from this library specifically await ImageGallerySaver.save(x);

ArtHoffmann commented 5 years ago

can u show me an example how youre saving the picture ?

andynvt commented 3 years ago

Same request here.

For now, in my Flutter APP, I have wrote the native code for Android channel to refresh Mediastore, so that the image file can be found in Album. But it is quite inconvenient to write native code on this. This is a common requirement.

I would like to improve it so that 'Intent.ACTION_MEDIA_SCANNER_SCAN_FILE' can be called in Flutter code easily. It is quite small code and it is not worth to create an individual plugin. So that I searched the current plugins library and would like to add the function there. Unfortunately, so far I did not find a proper plugin to add it.

I am not sure if it is ok to add the function here. Means, adding a method like, Image.refresh(file.path); And then in the plugin code(might be Java), to add like,

Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri uri = Uri.fromFile(new File(<filePath>));
intent.setData(uri);
sendBroadcast(intent);

Where <filePath> is the image file path and provided in Image.refresh(file.path);.

Thought?

Thank you!

Max Ma

does it work now?