Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using nearest neighbour interpolation for flutter image

Tags:

flutter

How do I get flutter to resize my Image widgets using nearest neighbour interpolation if the size of the widget is not the same as the asset size?

class PlayContainer extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Color.fromARGB(255, 0, 110, 255),
      child: SafeArea(
        child: Image(
          fit: BoxFit.contain,
          image: AssetImage("assets/knight.png")
        )
      )
    );
  }
}

This resizes the image correctly, but it is blurry due to the bilinear interpolation used to resize it.

Based on the source seems to be rather hard coded?

like image 328
Giffesnaffen Avatar asked Sep 16 '18 12:09

Giffesnaffen


People also ask

What is nearest Neighbour interpolation in image processing?

Nearest-neighbor interpolation (also known as proximal interpolation or, in some contexts, point sampling) is a simple method of multivariate interpolation in one or more dimensions.

What is the disadvantage of nearest neighbor interpolation?

The disadvantage of using the nearest-neighbor algorithm for image interpolation is the production of upscaled images with the most jagged-edges among other well-known algorithms5.

How does nearest Neighbourhood interpolation work and what is its advantage?

Nearest neighbour interpolation is the simplest approach to interpolation. Rather than calculate an average value by some weighting criteria or generate an intermediate value based on complicated rules, this method simply determines the “nearest” neighbouring pixel, and assumes the intensity value of it.

What is nearest interpolation method?

Round interpolation (also called nearest neighbor interpolation) is the simplest method, it just takes rounded value of the expected position and finds therefore the closest data value at integer position.


1 Answers

This is now possible in the master branch thanks to this Pull request:

I've added the possibility to set the filterQuality on Images. This was hardcoded.
The previously hardcoded value is set as default parameter.

Some images look better when scaled with no filter quality (like pixelart). That's why I added the parameter.

like image 113
Giffesnaffen Avatar answered Sep 28 '22 03:09

Giffesnaffen