Open weiminghuaa opened 3 years ago
@weiminghuaa Are you referring / using https://pub.dev/packages/cached_network_image/install plugin ?
@darshankawar Yes. I mean, I use the CachedNetworkImage memCacheWidth to reduce the memory usage of very large images. This method is effective for many image formats, such as webp and png, but it is not valid for gif. I see that CachedNetworkImage memCacheWidth is actually call ResizeImage resizeIfNeeded, so I want to ask if the problem lies in ResizeImage
@weiminghuaa
What platform are you trying this on ? Is it possible to provide a self contained code only using ReSizeImage
with a sample gif, that we can directly use to verify this ?
@darshankawar I have tested memory only using ReSizeImage with a sample gif. You can test the following code, no matter which way, the memory usage is 36.5M
class SampleItemDetailsView extends StatelessWidget {
const SampleItemDetailsView({Key? key}) : super(key: key);
static const routeName = '/sample_item';
@override
Widget build(BuildContext context) {
// origin
return Scaffold(
appBar: AppBar(
title: const Text('Item Details'),
),
body: Center(
child: Image.network(
"https://d1hzxpwavt5kus.cloudfront.net/home/16322955386612_74ec4a82-bd04-4e91-93ed-5594e1778cc2.gif",
)));
// resize image
return Scaffold(
appBar: AppBar(
title: const Text('Item Details'),
),
body: Center(
child: Image(
image: ResizeImage.resizeIfNeeded(
375, // test code, set small to test memory
null,
const NetworkImage(
"https://d1hzxpwavt5kus.cloudfront.net/home/16322955386612_74ec4a82-bd04-4e91-93ed-5594e1778cc2.gif",
)))));
// CachedNetworkImage
return Scaffold(
appBar: AppBar(
title: const Text('Item Details'),
),
body: Center(
child: CachedNetworkImage(
imageUrl:
"https://d1hzxpwavt5kus.cloudfront.net/home/16322955386612_74ec4a82-bd04-4e91-93ed-5594e1778cc2.gif", // width: MediaQuery.of(context).size.width,
width: MediaQuery.of(context).size.width,
memCacheWidth: (MediaQuery.of(context).size.width *
MediaQuery.of(context).devicePixelRatio)
.toInt(),
fit: BoxFit.cover,
),
),
);
}
}
body: Center( child: Image( image: ResizeImage.resizeIfNeeded( 375, // test code, set small to test memory null, const NetworkImage( "https://d1hzxpwavt5kus.cloudfront.net/home/16322955386612_74ec4a82-bd04-4e91-93ed-5594e1778cc2.gif", )))));
@weiminghuaa
If we consider above code snippet, since it uses core components and not 3rd party plugin, I see that above, you have provided only cacheWidth
and kept cacheHeight
as null
.
Looking at the documentation, it states Composes the provider in a ResizeImage only when cacheWidth and cacheHeight are not both null.
. So can you try by providing both parameters and see if it helps ?
https://api.flutter.dev/flutter/painting/ResizeImage/resizeIfNeeded.html
I have try by providing both width and height, it's not work.
@weiminghuaa How are you measuring the memory ? Can you compare it with a sample image (png or jpeg, basically non-gif image) and see if it resizes and reflects in the memory you are measuring ?
I use Dart DevTools measure the memory. There is no problem with png or jpeg, but gif.
Thanks for the update. I see the same behavior on latest stable and master.
Oh,it is since 2021,Now is 2024! Is there any progress?
CachedNetworkImage has memCacheWidth/memCacheHeight to reduce image memory, I think it implement by ResizeImage when look CachedNetworkImage src. But it's not work in gif, how to solve it?