Coder Social home page Coder Social logo

Comments (5)

TheJoeFin avatar TheJoeFin commented on August 20, 2024 1

I was able to finally solve this issue. I did so with the help of StackOverflow and Composition APIs.

This method removed the sub-pixel rendering or anti-aliasing effect I was seeing when using a standard Image or Viewbox uniform to fill scale option.

image

To see how:

private void LoadImageOnToCanvas()
{
mainImageCanvas.Children.Clear();
// from StackOverflow
// user:
// https://stackoverflow.com/users/403671/simon-mourier
// Post: read on 2023/12/28
// https://stackoverflow.com/a/76760568/7438031
// get visual layer's compositor
Compositor compositor = ElementCompositionPreview.GetElementVisual(mainImageCanvas).Compositor;
// create a surface brush, this is where we can use NearestNeighbor interpolation
CompositionSurfaceBrush brush = compositor.CreateSurfaceBrush();
brush.BitmapInterpolationMode = CompositionBitmapInterpolationMode.NearestNeighbor;
// create a visual
SpriteVisual imageVisual = compositor.CreateSpriteVisual();
imageVisual.Brush = brush;
// load the image
LoadedImageSurface image = LoadedImageSurface.StartLoadFromUri(new Uri(_imageFile.Path));
brush.Surface = image;
int size = isZooming ? ZoomedWidthSpace : _sideLength;
Width = size;
Height = size;
// set the visual size when the image has loaded
image.LoadCompleted += (s, e) =>
{
// choose any size here
try
{
imageVisual.Size = new System.Numerics.Vector2(size, size);
image.Dispose();
}
catch { }
};
// add the visual as a child to canvas
Grid tempGrid = new();
ElementCompositionPreview.SetElementChildVisual(tempGrid, imageVisual);
mainImageCanvas.Children.Add(tempGrid);
}

from simple-icon-file-maker.

michael-hawker avatar michael-hawker commented on August 20, 2024

@TheJoeFin is this what you need? 🦙 https://stackoverflow.com/questions/41210819/nearest-neighbor-rendering-in-uwp

from simple-icon-file-maker.

TheJoeFin avatar TheJoeFin commented on August 20, 2024

I am using ImageMagick to scale the source down to the different sizes. The images from that process are good.
The problem I am having is when displaying those small, say 16x16, images on the Image control within the Viewbox control they look blurred when scaling them up.

Is there a better way I should be "zooming in" on the small sizes? Maybe this is an issue with the Viewbox.

from simple-icon-file-maker.

michael-hawker avatar michael-hawker commented on August 20, 2024

I think the suggestion here is to use the BitmapTransform in the UI layer to scale the image back up to the target DPI/size to display in the Image over using Viewbox?

But that does seem a bit excessive.

What happens if you don't put the image in the Viewbox and just resize the Image control with the Uniform stretch - is it the same behavior then?

from simple-icon-file-maker.

TheJoeFin avatar TheJoeFin commented on August 20, 2024

I removed the Viewbox and have the same problem.

Here on the left is the preview in Simple Icon File Maker and on the right is the preview of the same file in the photos app. 🤔

image

from simple-icon-file-maker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.