How to load all gallary images quickly in flutter - flutter

I want to make a custom image picker in a custom bottom sheet. I did it using photo_manager package and it works, but it loads images with full resolution, so it is so slow and it gets slower as I scroll down to see more images.
how can I load gallary images into a bottom sheet so fast? (as fast as telegram chat image picker!)

There is a option for thumbnail:
Uint8List thumbDataWithSize = await entity.thumbDataWithSize(width,height); //Just like thumbnails, you can specify your own size. unit is px; format is optional support jpg and png.
I've used it with 400*400, and it's quite ok

Related

Reduce the image size in flutter

I am trying to reduce the image selected from gallery size from MB to KB enter by the use. How can I do that?
I want a textbox in which the user can enter the value to reduce the size and after pressing a button
the images are resizer
You can try this package which provides various functions for image manipulation, resizing, cropping and much more.
Take a look at code usage examples at this page.
You should be able to resize image for given ressolution, with proper calculations you could be able to resize it into given size also.
flutter_image_compress Plugin provides the functionality to compress image size and weight
See Full Example on Github
If you are using Image Picker Library then you can directly use something like this. This is useful if you want to save it in Firebase or similar backend.
ImagePicker imagePicker = ImagePicker();
PickedFile compressedImage = await imagePicker.getImage(
source: ImageSource.camera,
imageQuality:70, // depending on compression ratio
);
Else if you want to use it only for compression then you can use Flutter Image Compression.
To convert png(Image File) to PDF, you can use this pdf.
There is a new package called to crop and resize ImageCropper and flutter image compress .
It allows you to crop and resize the image to any or specified aspect ratio you want and can even compress the image.
Here is the link,
1.Image cropper https://pub.dev/packages/image_cropper
2.flutter image compress https://pub.dev/packages/flutter_image_compress

Want to resize a image with better resolution in swift

I have a image which is uploaded in the image cloud-cloudinary using the API.The response of the upload gives me the cloudinary uploaded url.
Example of one image is as given:
This image is of 120*67 which is uploaded.Now in my app,it looks like this.
The width of my image is as per the phone screen width and the height is fixed to 324.Now i want to resize this 120*67 image to the width and height of my image in the app without losing its clarity.I have made the content mode as scale to fill for the imageview.
Generally, scaling up (non vectorized) images without compromising their quality is not possible (without machine learning). Some software programs have complex algorithms to help with upscaling, but that's also to a limited extent.
You should upload a larger version of your image to Cloudinary, and request it downscaled to the desired resolution.
You should also check out responsive layout design.
If the image is vectorized (e.g - SVG), you need to make sure you're not requesting a rasterized version of it. I.E -
https://res.cloudinary.com/<cloud name>/image/upload/fl_sanitize/<image name>.svg
will keep the image vectorized.

Show gif while image is loading (wicket)

I am following this guide for displaying images in wicket How to load external Images
I see one problem and dont know how to solve it. Consider this piece of code
StaticImage img=new StaticImage( "icon", new Model(loadingGIFURL));
//get real image url
img.setDefaultModel(new Model(realURL))
It doesnt show the loading gif, because I override the DefaultModel. So how can I still show my loading gif but "preload" the real image and when the real image is downloaded then replace the loading gif with my image.
Note that I dont have a image source like base64, I only have the image url

Should I use png or jpg for my image and thumbnail?

I'm taking images from the camera or the camera roll and I'm saving them to core data using an ImageToDataTransformer class. I need to use these saved images in two different places in my app: 250x250 imageview and 50x50 imageview.
First, should I use png format for both imageviews?
Second, can I compress the image before I save it to core data, and what's the best way?
Third, should I save two different images, one for the big image and another for the thumbnail in a different view?
When Xcode builds your project, it automatically optimizes PNG files included in your project. So, I guess you should use PNG.
I don't know about runtime.
That would be a good idea if you have a table view and you want to show thumbnails. You wouldn't want to be loading the huge files, that would be excruciatingly slow.

Loading image slow my app down

I'm new to iphone dev, i'm just trying to get something done.
I do my first XML parser App. When my app launches i set a tableView with a custom cell. There is in the custom cell two labels and one image.
When the table view is launched i call my custom cell method which take the string od the image's adress and then make an url with it, a nsdata from the content of an url than i create my image with the content of this data.
But my table view is really really slow even on simulator.
what is the best way to display images on iphone via the internet ? ?
i know they have to be in a png format but even with png it is too slow
thanks for all
i use :
> NSURL *imgUrl = [NSURL URLWithString:_text];
> NSData *imgData = [NSData dataWithContentsOfURL:imgUrl];
> limage.image = [UIImage imageWithData:imgData];
Is your image saved at its final resolution? Say you want to display a 25x25 pixel image in the table, is the file saved as a 25x25 image or is it saved as some higher resolution? This will cause some slowness. However you should be loading the image in a background thread so that when scrolling the scrolling isn't holding up waiting for the image to load. Remember that doing network transfer to get the image is most likely the longest part of the process. You should also cache the image in some way instead of just assigning the image to the limage.image property. This way it won't redownload the image each time it redraws the cell.
Edit
Also you don't have to use PNG images for the pictures in the table cells. You can use regular JPG or GIF images if you want. The image format used should be what ever format is appropriate for the type of image content you will have. You only have to use PNGs for the icons, and splash screens, although it is preferred to use PNG in all embedded resources.
[NSData dataWithContentsOfURL:imgUrl];
Will certainly slow your app down since it will wait for your image to be done loading, called a synchronous call. What you really want is asynchronous calls for fetching the content of the image.
Have a look at http://joehewitt.com/post/the-three20-project/ where you'll find an nice subclass of UIImage that supports handling loading of images by url.