flutter_photo_manager icon indicating copy to clipboard operation
flutter_photo_manager copied to clipboard

[Help] Get File from thumbnail

Open momoDragon opened this issue 3 years ago • 14 comments

Is there a way to get file from the thumbnail?

tried this but doesn't work

          Uint8List? list = await assetEntity.thumbDataWithSize(400, 400);
          File file = File.fromRawPath(list!);

momoDragon avatar Sep 21 '21 06:09 momoDragon

You can create a new File object at a desired path, and call writeAsBytes with the thumbnail data.

vishnukvmd avatar Sep 21 '21 08:09 vishnukvmd

Yea i tried that and it works, but seems like i would store double the files. one from the package itself when it creates thumbnails and then another copy of my own in the temp directory. Can it be a feature request to have a method like getFileFromThumbnail() ?

momoDragon avatar Sep 22 '21 04:09 momoDragon

You could perhaps delete the one you have generated after you've made use of it?

If you could explain your exact use case, it would make it easier to suggest a solution.

vishnukvmd avatar Sep 22 '21 05:09 vishnukvmd

My use case is that i need File as input for google_ml_kit package for ML processing. My concern is not just the space but also the time taken for saving the file. it would definitely be faster if i can get access to the thumbnail file directly, rather than writing to file then reading it again. I am trying to optimize the process because there can be scenarios of 100s of images.

momoDragon avatar Sep 22 '21 05:09 momoDragon

AFAIK the InputImage accept Uint8List. image

AlexV525 avatar Sep 22 '21 05:09 AlexV525

yes i am aware of that too but i am not sure about InputImageData https://pub.dev/documentation/google_ml_kit/latest/google_ml_kit/InputImageData-class.html. Particularly these inputImageFormat → InputImageFormat Format of the input image. final planeData → List<InputImagePlaneMetadata>? The plane attributes to create the image buffer on iOS. [...] final

momoDragon avatar Sep 22 '21 05:09 momoDragon

Bytes do not have these data. And also AssetEntity might not have all of it either

momoDragon avatar Sep 22 '21 05:09 momoDragon

You can use the .file getter at present for your request, though it didn't provide any thumbnail options.

AlexV525 avatar Sep 22 '21 05:09 AlexV525

You can use the .file getter at present for your request, though it didn't provide any thumbnail options.

Yup i tried that too but the file is unnecessarily large, causing ML Kit results to be slow. So for my case, using the full file is not an option.

momoDragon avatar Sep 22 '21 05:09 momoDragon

tried this but doesn't work

          Uint8List? list = await assetEntity.thumbDataWithSize(400, 400);
          File file = File.fromRawPath(list!);

Regarding the first question, how it behave when you said doesn't work?

AlexV525 avatar Sep 22 '21 05:09 AlexV525

   Uint8List? list = await assetEntity.thumbDataWithSize(400, 400);
      File file = File.fromRawPath(list!);

      print(file.path);
      print(await file.readAsBytes());

Output: Screenshot 2021-09-22 at 1 42 17 PM

momoDragon avatar Sep 22 '21 05:09 momoDragon

Can you make a minimal repo that includes ML Kit and this plugin to reproduce this issue?

AlexV525 avatar Dec 23 '21 14:12 AlexV525

Hello, were you able to come up with a solution? I have the same use-case of wanting to use a file with ml kit but without the lengthy load times of .file with large files.

TylerKerch avatar Feb 23 '22 06:02 TylerKerch

See comments above. InputImage accepts Uint8List.

AlexV525 avatar Feb 23 '22 16:02 AlexV525