how to save uint8list to gallery as png - flutter

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);

Related

Images built on the flutter do not output properly to the widget

i used CircleAvatar and input backgroundImage: AssetImage('assets/image's name')
also i modified pubspec.yaml (I used command / to assets line)
but, I don't see the image in my emulator..
I don't know what caused it.
I attach an image for a detailed explanation.
The picture of the squirrel on the left is the image I want.
However, the widget shows a blue circle.
you forgot to put .jpeg after the name
In Flutter, when you are trying to display an image, it's important to include the proper image file extension (e.g. .jpeg, .png, .gif, etc.) at the end of the file name. If the extension is missing, the image won't be displayed. To resolve this issue, simply add the correct extension to the end of the file name in the code that defines the image path. For example, if the original code reads
Image.asset("example_image")
change it to
Image.asset("example_image.jpeg")

how to: save image data to gallery [Flutter]

I have 1 question:
I use a library and it returns the Image data type, so how do I save or share the image in the library of my device?
code:
Image image = await HmsScanUtils.buildBitmap(request);
https://pub.dev/packages/gallery_saver
This plugin saves images and videos to gallery/photos.
You need to provide a path to the file that you want to save like below:
GallerySaver.saveImage(path)
You can use this package
https://pub.dev/packages/gallery_saver.
If you dont understand any documentation given on this page then you can simply follow the following tutorial by Johannes
https://www.youtube.com/watch?v=JILcQLZvjKE

Path Provider Using and Asset Problems

I want to add an image that I added to my application from the phone's gallery to the list and call it with Image.asset as a String value.
I managed to get the image with ImagePicker. Unfortunately, there is no next. I don't know exactly how to do this.
In short: I will select an image from gallery with ImagePicker and replace it with "Image.file"
I will do it by converting it to String value with Image.asset.
You have to use image.file or image.memory to load an image from ImagePicker.
image.asset is for images that already exist within your app.

how to use an specific image icon in flutter local notification?

the application's logo is PNG,so in android lollipop this icon convert to be a white square. so i need to use another image in JPG format for flutter local notification.
i have two questions:
first:
where should i put this image?
second:
how could i access this image?
the code is :
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('#mipmap/ic_launcher');
You should create a new image with size 48x48. You can have it as png as well as long as there is transparency and image itself is white.
Let's call this file ic_notification.png
Navigate to your project root directory. You will find android directory. Expand it see following directory in nested order
app
src
main
res
mipmap
if you don't see mipmap folder or different versions of mipmap folder, like mipmap-xxxdpi or mipmap-hdpi etc, create mipmap folder there and put your icon file in that folder.
On flutter side, replace AndroidInitializationSettings('#mipmap/ic_launcher'); with AndroidInitializationSettings('#mipmap/ic_notification'); (without .png)
You should have different icon for app launcher and notification as they serve different purpose.

Picked gallery Image path flutter

I'm working on a app where I would like to get the local path of the selected/picked image from my mobile gallery instead of image_picker path. I have used image _picker to pick an image from the gallery. When I print the path of the selected image it showing something like this /data/user/0/coffy.testapp/cache/image_picker5380473371212438250.jpg instead I need a path of the image like /data/emulated/downloads/021545.png (The path I can see in my mobile when I click the image details of a particular image);
You need to access local storage and select from there.
https://flutter.dev/docs/cookbook/persistence/reading-writing-files
https://pub.dev/packages/path_provider