-1

Question

How can I scale an image in XAML quickly without anti-aliasing applied?

Background

I am trying to make a pixel editor as a Windows 8 XAML/C# app. I'm using c#/XAML because most of my experience is with c#/WPF.

  • Method 1: WriteableBitmap + Image control.

    Originally, I used a WriteableBitmap to store and edit an image. That image is displayed in a resized XAML Image control. The problem is that the image does not get scaled properly because of anti-aliasing. (XAML does not seem to provide the BitmapScalingOptions that are available in WPF)

    anti-aliased version

  • Method 2: Redrawn WriteableBitmap + Image control.

    Next I tried writing my own scaling, where I take my original image and write to a larger WriteableBitmap so that the scaled image is pixelated. The scaled image is then presented inside a XAML Image control. This process is slow and inefficient.

    enter image description here

  • Method 3: SharpDX + Direct2d ??

    I am pretty sure a solution exists somewhere between SharpDx, SurfaceImageSource, and Direct2d. Event still, I can't quite figure out how to display a SharpDx.WIC.Bitmap inside a Windows.UI.Xaml Image control, and am generally getting lost in the documentation.

What exactly is a recommended setup for achieving my desired end? Are there c# samples available which might point me in the right direction?

Amanduh
  • 1,233
  • 1
  • 13
  • 23

1 Answers1

0

I don't know if you mean by scaling it by resizing it with the mouse or just with a button click to auto scale to a predetermined size.

But the thing you can do is to use an Image panel and then, just set it to image.Stretch = Stretch.Fill; so if you override and create a method for the Resize event of the Image Panel, your image will take the size to fill the Image panel.

c_str
  • 369
  • 1
  • 4
  • 14
  • This method does not work because of the anti-aliasing I mentioned above. I will add more details to my question... – Amanduh Jul 12 '14 at 20:21