Repository navigation
Description
Steps to reproduce
- Take a large asset with thin, high-contrast details, e.g. a 1024×1024 PNG logo.
- Display it at ~120 logical pixels twice: once plain, once with
cacheWidthset to the display size in physical pixels (the usage recommended for saving memory). - Compare the two.
Expected results
Both images look the same (or nearly so). cacheWidth should only reduce memory, since the image is never drawn larger than the cache size.
Actual results
The cacheWidth version is visibly aliased: thin lines and curved edges are jagged ("pixelated"). The plain version, minified on the GPU with mipmaps (FilterQuality.medium), is smooth.
This was reported by users of our app: Otzaria/otzaria#1747 (logo decoded from 1024 px to ~120 px).
Cause
The decode-time resize uses bilinear sampling without mipmaps, so for large reduction ratios (~8× here) each output pixel samples only 2×2 of the ~8×8 source pixels it covers:
engine/src/flutter/lib/ui/painting/image_decoder_impeller.cc(ResizeOnCpu):
scalePixels(..., SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kNone))engine/src/flutter/lib/ui/painting/image_decoder_skia.cc(ResizeRasterImage): same sampling options.- The Impeller GPU path (
blit_pass->ResizeTexture(dest_texture, resize_texture)) also resizes from the non-mipmapped source; mipmaps are generated only for the destination.
Possible fixes: use mipmapped sampling (SkMipmapMode::kLinear) or SkCubicResampler for the CPU path, or downscale in successive halving steps / generate source mipmaps before the GPU resize, at least when the reduction ratio is greater than 2.
This is the same problem as #56239, which was closed by #184549. That PR adds logical-pixel sizing to ResizeImage but does not change the resize quality, so the original quality issue is still present.
Code sample
Code sample
import 'package:flutter/material.dart';
// Any large asset with thin details, e.g. a 1024x1024 logo.
const asset = 'assets/logo_1024.png';
const size = 120.0;
void main() => runApp(const MaterialApp(home: Demo()));
class Demo extends StatelessWidget {
const Demo({super.key});
@override
Widget build(BuildContext context) {
final dpr = MediaQuery.devicePixelRatioOf(context);
return Scaffold(
body: Center(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
// Smooth: full decode, GPU minification with mipmaps.
Image.asset(asset, width: size, height: size),
const SizedBox(width: 24),
// Jagged: decode-time resize, bilinear without mipmaps.
Image.asset(
asset,
width: size,
height: size,
cacheWidth: (size * dpr).ceil(),
),
],
),
),
);
}
}Flutter Doctor output
Doctor output
Flutter 3.47.2 • framework revision d3b14c8769 (2026-08-26)
Windows 11 x64The resize code quoted above is identical on the current master.
Activity
mbcorona commentedon Oct 5, 2026
Hi @palmoni5, thanks for the clear writeup and root cause.
Routing to team-engine for evaluation.
gaaclarke commentedon Oct 5, 2026
@palmoni5 can you provide an image of the aliasing you are seeing? Can you also please add an example image that demonstrates your problem with your provided code please?
palmoni5 commentedon Oct 5, 2026
Thanks! Here is the output of the exact code sample above, rendered on a real Windows device (Flutter 3.47.2, debug, devicePixelRatio 1.0), captured with
RenderRepaintBoundary.toImage.Source image (1024×1024 PNG): https://github.com/Otzaria/otzaria/blob/dev/assets/icon/iconnew.png
1:1 capture — left: plain
Image.asset, right:cacheWidth: 120:4× nearest-neighbor zoom of the same capture:
The
cacheWidthversion shows stair-stepped edges along the curves and the thin outlines, while the plain version (full decode, GPU minification with mipmaps) is smooth.