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. and
. 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?