I found that my problem lies in a method I used to resize the picture: Here's the code:
private WriteableBitmap ResizeImage(BitmapImage original, double destWidth, double destHeight)
{
Image image = new Image()
{
Source = original,
Stretch = Stretch.UniformToFill
};
image.UpdateLayout();
int origWidth = original.PixelWidth;
int origHeight = original.PixelHeight;
ScaleTransform st = new ScaleTransform();
st.ScaleX = destWidth / (double)origWidth;
st.ScaleY = destHeight / (double) origHeight;
WriteableBitmap result = new WriteableBitmap((int)destWidth, (int)destHeight);
result.Render(image, st);
result.Invalidate();
return result;
}
I tested my code under 2 circumstances:
- pass picture from "Camera Roll"
- pass picture from other albums
My code will work on "Camera Roll" pictures, but it will return me a whole black result for the pictures loaded from other albums.
In either of these circumstances, despite the bitmap is whole black or not, this method will return me the bitmaps correct width and height.
For these two scenario, I'm using the same method to load pictures, but why only pictures from camera roll can be displayed but those who come from other albums cannot?
I know the WriteableBitmapEx library has the method to do resize perfectly. But I just curious about why my method won't work? Could any one help me with that?
Imagecontrol. There may be something wrong with your code. What do you mean by "this method doesn't work", nothing is displayed, the old picture is still displayed, an exception is thrown, ... ? - Kevin Gosse