I'm trying to load an image in a local path to a Silverlight image control. This is an out of browser application. When I load the image using a stream it's always flipped upside down.
Any idea why? This happens for large images only.
FileName
here gives the full path to local file system, like C:\imageFullPath\image.jpg
.
Please help. Following is the code.
------ In Model side------------------------
public BitmapImage DisplayImage
{
get
{
if (!string.IsNullOrWhiteSpace(FileName))
{
var b = new BitmapImage();
b.SetSource(System.IO.File.OpenRead(FileName));
return b;
}
return null;
}
}
------ In Silverlight View side------------------------
<Image Source="{Binding DisplayImage, Mode=TwoWay}" Width="450" Height="250" Margin="0,0,0,0"/>
What i see when debugging
BMP
are normally stored "upside-down" with the pixels in reverse order from bottom to top, but can use a negative height in the file header to indicate the image is stored top-to-bottom, so perhaps you have such an image.Does this happen with all images, or just that one?
You could try changing the way the image is loaded, using a
Uri
in the constructor instead of callingSetSource()
with aStream
, as it may account for the header and read the file differently:Or, if that doesn't help, you can apply a transform to flip every image, but that doesn't solve the underlying problem: