1

I am working on a Windows phone 8 chat application. I need to be able to send images. I am able to send images with low resolution but when I try to send high resolution images (10240 x 6400) the resulting image is not what I expected. This is my high resolution image and this is the image that is being displayed. As you can see only some portion of the image is being showed while the remaining area is grey. I think the problem is with how I am cropping and/or re-sizing the images. I am converting my image into a WriteableBitmap object and resizing it in this method. The parameter requiredImageSize = 800.

     private WriteableBitmap ResizeLargeWriteableBitmapImage(WriteableBitmap bitmap, int requiredImageSize)
    {
        WriteableBitmap resized;

        int tnWidth = 0;
        int tnHeight = 0;

        if (bitmap.PixelWidth >= bitmap.PixelHeight)
        {
            if (bitmap.PixelWidth <= requiredImageSize)
                tnWidth = bitmap.PixelWidth;
            else
                tnWidth = requiredImageSize;
        }
        else if (bitmap.PixelHeight >= bitmap.PixelWidth)
        {
            if (bitmap.PixelHeight <= requiredImageSize)
                tnHeight = bitmap.PixelHeight;
            else
                tnHeight = requiredImageSize;
        }

        if (tnWidth > 0)
        {
            tnHeight = (bitmap.PixelHeight * tnWidth) / bitmap.PixelWidth;

        }
        else if (tnHeight > 0)
        {
            tnWidth = (bitmap.PixelWidth * tnHeight) / bitmap.PixelHeight;
        }

        resized = bitmap.Resize(tnWidth, tnHeight, WriteableBitmapExtensions.Interpolation.Bilinear);

        return resized;
    }

and I am saving the WriteableBitmap object as a JPEG image

    writableImage.SaveJpeg(msThumbnailImage, writableImage.PixelWidth, writableImage.PixelHeight, 0, 100);

Then I am saving the image into local storage and displaying it (where it is displaying as I said before). Why is this happening. Have I done anything wrong in the code?

Raj123
  • 971
  • 2
  • 12
  • 24

1 Answers1

0

I'd suggest that you don't need to use the bitmap.Resize() method.

You could simply take the width and height parameters that you find in your method (tnHeight and tnWidth). Then use those as the pixelWidth and PixehHeight in the writeableImage.saveJpeg() method. That should reduce the resolution of the saved jpeg to your desired size.

JayDev
  • 1,340
  • 2
  • 13
  • 21
  • I didn't understand whether your answer is a solution for my problem or a suggestion for my method. If its the former, no luck there. – Raj123 Jul 09 '14 at 07:28