I am trying to view Gigapixxel image in flutter App.I want to Optimize the image size for reduce Data Usage and save the memory when open the image. User should be able to Zoom that image. How I can do that in Flutter ? (I want to zoom Image as google map)
Use this dependency Flutter Native Image its easy to use and will do the job you are looking for. It will reduce the size of the image and for zooming in just use this dependency and wrap it up with any widget you want. Photo View
Simple Usage of photo view
Container(
child: PhotoView(
imageProvider: AssetImage("your asset"),
)
);
Flutter native image:
To crop
File croppedFile = await FlutterNativeImage.cropImage(file.path, originX, originY, width, height);
To compress image:
File compressedFile = await FlutterNativeImage.compressImage(file.path,
quality: quality, percentage: percentage);
You have to give it a file from the file system and optionally provide a quality (1-100) and a resizing percentage (1-100). Each platform will use it's proper tools to handle the resizing.
The documentation of each dependency is your friend have a look at it, read a bit and use the code according to your needs.
Related
So currently I'm trying to render a large image for example:
I tried CachedNetworkImageProvider from pub_dev.
I also tried various different Providers with combination of Image widget. None of them worked.
The only widget that allows me to render the image is photo_view which renders the 4k image but has Zoomable feature that I don't want to have.
How can I remove this feature and fit with BoxFit?
Libraries tried to render the image:
extended_image
image_ink_well
flutter_advanced_networkimage
When using PhotoView you can disable the zoom functionality.
IgnorePointer( // The PhotoView widget thinks there's nothing happening
// because you're catching any clicks that happen here.
child: PhotoView(
minScale: PhotoViewComputedScale.covered,
maxScale: PhotoViewComputedScale.covered,
),
),
You can read more about the PhotoView class here: https://pub.dev/documentation/photo_view/latest/photo_view/PhotoView-class.html
I searching an days for this question.
I want to Crop Images like that, in flutter:
GIF Source: https://github.com/ArthurHub/Android-Image-Cropper
The closest lib for this solution is the Image Lib, that lib offers manipulate images and crop, but i want to crop images in UI level like this gif. All libs I found dont offers that.
There is no widget that performs all that for you. However, I believe that it is possible to write that natively in flutter now. I don't have time at this particular moment to do it for you, but I can definitely point you in the right direction.
You're going to need to load the image in such a way that you can either draw it onto a canvas or use a RawImage to draw it rather than using the Image widget directly.
You need to figure out a co-ordinate system relative to the image
You'll need to find a way of drawing the crop indicator - you could do this either by drawing directly on the canvas or possibly using some combination of GestureDetector/Draggable/DropTarget. I'd suggest that sticking to Canvas might be the easiest to start.
Once the user has selected a part of the image, you need to translate the screen co-ordinates to picture co-ordinates.
You then have to create an off-screen canvas to draw the cropped image to. There are various transforms you'll have to do to makes sure the image ends up in the right place.
Once you've made the off-screen crop, you'll have to display the new image.
All of that is quite a lot of work, and probably a lot of finessing to get right.
Here's examples for a couple of the steps you'll need to do, but you'll have to figure out how to put them together.
Loading an image:
var byteData = await rootBundle.load("assets/image.jpg");
Uint8List lst = new Uint8List.view(byteData.buffer);
var codec = await UI.instantiateImageCodec(lst);
var nextFrame = await codec.getNextFrame();
var image = frameInfo.image;
Displaying an image on a canvas:
https://docs.flutter.io/flutter/dart-ui/Canvas/drawImageRect.html
https://docs.flutter.io/flutter/rendering/CustomPainter-class.html
Writing an image to a off-screen canvas:
ui.Image getCroppedImage(Image image, Rect src, Rect dst) {
var pictureRecorder = new ui.PictureRecorder();
Canvas canvas = new Canvas(pictureRecorder);
canvas.drawImageRect(image, src, dst, Paint());
return pictureRecorder.endRecording().toImage(dst.width.floor(), dst.height.floor());
}
You'll probably need to do something like this answer for getting the local coordinates of mouse/touch gestures.
Some advice - I'd start as simple as possible, not thinking about performance to start (i.e. draw everything each paint if needed, etc). Then once you get the basics working you can start thinking of optimization (i.e. using a RawImage, Transform, and Stack for the image and only re-drawing the selector, etc).
If you need any additional help let me know in a comment and I'll do my best to answer. Now that I've been writing about this a bit it does make me slightly curious to try implementing it so I may try at some point, but it probably won't be soon as I'm quite low on time at the moment. Good luck =D
The image_cropper plugin does exactly what you are looking for.
I'm still new to use flutter, it is an interesting language. Just need to know.
#override
Widget build(BuildContext context){
return Center(
child : Image.asset(
"animated.gif"
)
);
}
If I build an animated image widget with Image.asset, is that possible to know when the animation finish, jump to the specific frame of the image just custom, and add a listener, or is there another way to achieve that?
The Image widget does not expose the progress of the animated asset.
However, you can use the lower level APIs to get more control.
If all you need is visibility into when frames are scheduled, you can work directly with the MultiFrameImageStreamCompleter. Look at the implementation of the Image widget for an example of how to get an image stream completer and use it.
Jumping to a specific animation frame is more tricky as the animation formats encodes deltas from previous frame and thus does not support random seek. One way to achieve that would be to decode and cache all frames, you can use the ui.Codec API to decode frames yourself and cache them. Note that doing this will consume a potentially large amount of memory.
Whenever I add an image using the image widget in ImpressPages 4.2.5, the image is resized to the actual width of the parent container. However, as I use a responsive design, I need the image in full resolution. Otherwise, the images will look blurry on high dpi screens (e.g. Smartphones or Retina screens).
Is there a way to prevent the image widget from resizing the images?
Try to increase the image size in theme options (theme.json).
Another option is to create a new skin for that widget to output original image and not resized one. Here's an article about skins - http://www.impresspages.org/docs/widgets#skin
I'm making a game were you can set the background image yourself.
The selected image is resized to make it fit the purpose, and then i want to load the picture into pygame.
I've something like:
image = Image.open('file')
image.thumbnail(size, Image.ANTIALIAS)
And now I want to load image into pygame.
of course I can use:
image.save(outfile, "JPEG")
background = pygame.image.load('outfile')
Is there a nice way without having to save the image to my hard drive?
Or is it possible that pygame resizes the image?
You can use pygame.transform.scale() to resize an image:
pygame.transform.scale()
resize to new resolution
scale(Surface, (width, height), DestSurface = None) -> Surface
Resizes the Surface to a new resolution. This is a fast scale operation that does not sample the results.
An optional destination surface can be used, rather than have it create a new one. This is quicker if you want to repeatedly scale something. However the destination must be the same size as the (width, height) passed in. Also the destination surface must be the same format.
So you don't have to use PIL.