WinRT Blit image quality

Apr 26, 2014 at 4:10 PM
Edited Apr 26, 2014 at 4:13 PM
Hello,
I might not see the trees for the wood here. I have several smaller WriteableBitmaps and want to blit them into a larger one in a Windows Store 8.1 app.

When I copy pixel by pixel, I get the result on the right in the following image. When using Blit, I get the left one. Both sections are not the same but there is an obvious quality difference :-/. What am I doing wrong?

Any help appreciated.

Andreas

Image

Source code:
Blit:
dest.DrawInto(backgroundImage, xDestOffset, yDestOffset, 0, 0, backgroundImage.PixelWidth, backgroundImage.PixelHeight);

 public static void DrawInto(this WriteableBitmap dest, WriteableBitmap backgroundImage, int xDestOffset, int yDestOffset, int xstart, int ystart, int xend, int yend)
{
  Rect destRect = new Windows.Foundation.Rect(xDestOffset, yDestOffset, xDestOffset + xend-xstart, yDestOffset + yend-ystart);
  Rect srcRect = new Windows.Foundation.Rect(xstart, ystart, xend-xstart, yend-ystart);
  dest.Blit(destRect, backgroundImage, srcRect, WriteableBitmapExtensions.BlendMode.None);
 }
Get/SetPixel:
 for (int x = 0; x < backgroundImage.PixelWidth; x++)
{
  if (x +xDestOffset >= dest.PixelWidth) {
    break;
  }
  for (int y = 0; y < backgroundImage.PixelHeight; y++)
  {
    if (y + yDestOffset >= dest.PixelHeight)
    {
      break;
    }
    var color = backgroundImage.GetPixel(x, y);
    dest.SetPixel(x+xDestOffset, y+yDestOffset, color);
  }
}
Coordinator
Apr 28, 2014 at 10:02 AM
This should actually work. Double check the coordinates and maybe try a different BlendMode like Alpha just to rule out this is not the issue.
Marked as answer by andreasbalzer on 4/28/2014 at 11:02 AM
Apr 28, 2014 at 7:02 PM
Thanks for your reply. Indeed there has been a coordinate issue. :-/ The rects are (horizontal start point, vertical start point, width, height) instead of (horizontal start, vertical start, horizontal end, vertical end). It would be nice if the documentation can be updated.

So it has to be:
dest.DrawInto(backgroundImage, xDestOffset, yDestOffset, 0, 0, backgroundImage.PixelWidth, backgroundImage.PixelHeight);

 public static void DrawInto(this WriteableBitmap dest, WriteableBitmap backgroundImage, int xDestOffset, int yDestOffset, int xstart, int ystart, int xend, int yend)
{
  Rect destRect = new Windows.Foundation.Rect(xDestOffset, yDestOffset, xend-xstart, yend-ystart);
  Rect srcRect = new Windows.Foundation.Rect(xstart, ystart, xend - xstart, yend - ystart);
  dest.Blit(destRect, backgroundImage, srcRect, WriteableBitmapExtensions.BlendMode.None);
 }