BitmapImage size restrictions in Silverlight

ⅰ亾dé卋堺 提交于 2019-11-30 19:36:04

问题


I'm making a Windows Phone 7 application which involves getting large images from the web and 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


回答1:


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.



来源:https://stackoverflow.com/questions/3890520/bitmapimage-size-restrictions-in-silverlight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!