BitmapImage size restrictions in Silverlight
I'm making a Windows Phone 7 application which involves getting large images from the web an开发者_如何学God putting it in a ScrollViewer
for the user to scroll through. I think I'm hitting a limitation of BitmapImage
, though, as the image seems to get cut off at 2048 pixels in either height or width.
Is this a known limitation of Silverlight BitmapImage
and is there some other class to use in this case to allow scrolling through the large images?
Thanks
Yes, there is a limit of 2k x 2k. This is limitation and a workaround are described in the white paper "Creating High Performing Silverlight Applications for Windows Phone" http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=3a8636bf-185f-449a-a0ce-83502b9ec0ec
Size Limitations: Since the Windows Phone camera is 5 MP and the screen resolution is smaller than on other platforms, the limits for images that can be processed are 2k x 2k pixels. Anything larger than that will be automatically sampled at a lower resolution and the image will lose some richness. Processing Images Larger than 2k x 2k There are scenarios where you need to process images larger than 2k x 2k, e.g. Photo editor, or cropping images. In those scenarios, you can process the images that are larger than 2k x 2k into a file, and then display a portion that fits into 2K x 2K. You can use the combination of WriteableBitmap with LoadJpeg to do it. Example #5 – LoadingLargeImages
XAML:
<StackPanel>
<Image Height="3000" Width="3000" Name="image1" Stretch="Fill" />
<Button Content="Load" Height="70" Width="152" Click="btnLoad_Click" />
</StackPanel>
Code Behind:
private void btnLoad_Click(object sender, RoutedEventArgs e)
{
StreamResourceInfo sri = null;
Uri uri = new Uri("LoadJpegSample;component/Test3k3k.JPG", UriKind.Relative);
sri = Application.GetResourceStream(uri);
WriteableBitmap wb = new WriteableBitmap((int)this.image1.Width, (int)this.image1.Height);
Extensions.LoadJpeg(wb, sri.Stream);
this.image1.Source = wb;
}
Things to Know When Using Larger than 2k x 2k Images:
- It is significantly slower to display
- Do NOT use it for animation or panning scenarios.
The Resize method of the WriteableBitmapEx can also be used for this task if no JPEG stream is available.
精彩评论