I'm currently working with Image picker for flutter. But when I pick video with Image Picker I only get some random .jpg file instead of .mp4 file. What is causing this issue?
PickedFile video = await ImagePicker().getVideo(source: ImageSource.gallery,);
When I print the Picked file I receive following:
I/flutter (25199): File: '/data/user/0/com.example.checkshopsonline/cache/image_picker2738786264491852340.jpg'
Am I missing some configuration with ImagePicker?
I have the same issues, but I downgraded to image_picker: 0.6.2 and it is working well. But be careful the image_picker: ^0.6.7+21 return type is PickedFile but older version is File.
Reference link: https://github.com/flutter/flutter/issues/52419#issuecomment-723750599
Related
I'm using the flutter image_picker plugin. I can use
final ImagePicker picker = ImagePicker();
final List<XFile> images = await picker.pickMultiImage(imageQuality: 60);
After a user has picked multiple images for their post and exit out, they can always go back and select more images - in which case I want the images already selected to be "pre-selected". The API has no way to do this I think, so I'm wondering if there is a similar/reliable plugin that can do this and is well supported.
I've googled and found multiple plugins for image picking - and none of them seem to support this feature. I'm tempted to try and roll my own but would prefer to find a plugin if one exists. Any recommendations I could try?
As I said in the title, I'm trying to share files converting an image file to PNG format. I have tried to use the packages share_plus and social_share. I have this code:
img.Image? image = img.decodeImage(File(imageXFile.path).readAsBytesSync());
final imageFile = File('${appDir.path}/$fileName.png');
imageFile.writeAsBytesSync(img.encodePng(image));
setState(() {
_items.add(new Item(fileName, imageFile));
});
I'm trying to share the file using imageFile.path. I also tried including the image/png as mimeType, but still get the original file name and extension when I share the file.
UPDATE: I tried to find a solution for this bug, but nothing yet. It appears that is not a share_plus issue, image package neither. I printed the uri and mimeType in share_plus Kotlin code before start the activity and I got the right infos (png mimetype and the .png extension). I don't know how to proceed now.
My last (and unsuccessful) test was this:
final XFile? imageXFile = await _picker.pickImage(source: ImageSource.gallery);
final imageFile = File('${appDir.path}/$fileName.png');
imageFile.writeAsBytesSync(await imageXFile.readAsBytes());
Share.shareFiles([imageFile.path], mimeTypes: ["image/png"]);
I tried to pick a PNG image, save it and share it immediately, but still share the image as JPG.
OBS: While I was writing this update, I noticed that when I share with Telegram (as uncompressed file), it will be sent as JPG. When I share with Outlook, it is attached as PNG (with the name and extension that I want to).
I'm working on a project that captures a screenshot of a widget and saves it in gallery.
my problem is there is few save to gallery packages in flutter and I tries almost all of them!
they save images as jpg which adds extra black bars around my widget which I don't want them to be there.
is there any package to save images to gallery in PNG format?
I've found the solution after 2 days of struggling with that.
you should save file as PNG to device path then use image_gallery_saver
package to save it as file
File('$dir/file_name${DateTime.now()}.png').writeAsBytes(pngBytes!);
final result = await ImageGallerySaver.saveFile(imagePath);
You can save image to gallery by using Image_gallery_saver plugin.image_gallery_saver
. For the black bars , you have to make sure that the screenshot is attached to the widget , what you want it image.
await ImageGallerySaver.saveImage(uint8list blob);
Hi I am using the flutter camera plugin and it works fine, the main issue I am having is that I can't find a way to tell the plugin the image file name when taking the picturee, in android using Kotlin this would be something like:
photoUri = FileProvider.getUriForFile(requireActivity(), "io.awesomedomain", photoFile) // build uri on the app storage space and specific file name -> photoFile.
captureImageIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri) // define the pic name before picture is actually taken by the camera.
startActivityForResult(captureImageIntent, REQUEST_PHOTO) // start the camera
I am currently just renaming the picture file name after the picture XFile returns from the flutter camera plugin but this doesn't feel optimal so I am wondering if I am missing something. Is it possible to specify the file name in advance to the flutter camera plugin?
I am currently using the latest available version at the moment: camera: ^0.7.0+2
OK, it looks like I had a misunderstanding of the Camera plugin, I noticed that the returned XFile places the picture in the cache directory and actually provides a method to save the picture to a more definitive storage xfile.saveTo so I did:
var appDir = appDocDirectory.parent.path; // get app directory
file.saveTo('$appDir${Platform.pathSeparator}files${Platform.pathSeparator}${weightPicture.pictureFileName}');
So the picture is properly saved under $myAppDir/files/picName.jpg where the files is a directory I configured to have permission to write to and the picName is defined by the application as I wanted.
Info:
Package: image_picker plugin for flutter, version 0.6.3+1
Android build only, no IOS
Problem:
This is my method to pick an image:
Future<void> pickImage(ImageSource source) async {
File selected = await ImagePicker.pickImage(source: source);
print(selected?.path);
imageFilePath = selected?.path ?? imageFilePath;
}
=> When using ImageSource.gallery, when choosing a picture which is not in cache, 'selected.path' prints null. When selecting a picture which is in cache, it does retrieve it, 'selected.path' prints:
/data/user/0/be.etnic.parrainage_mcf/cache/image_picker2517179621202627006.jpg
Anyone knows what causes this problem and how I can solve it?
Sidenotes:
I can also pick an image by making a picture directly with ImageSource.camera, this doesn't give me any problems.
I'm not 100% sure that the selected pictures that return null
are not in cache, but the pictures that do return correctly from
choosing from the ImageSource.gallery all come from that
cache-folder
I don't have any permissions set in my AndroidManifest.xml
(other than Internet permission)
Based on this link https://github.com/flutter/flutter/issues/41459#issuecomment-563986851, following should solve the problem:
android:requestLegacyExternalStorage="true"