Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin表单Android显示图片引发异常_Android_Image_Xamarin_Xamarin.forms_Resolution - Fatal编程技术网

Xamarin表单Android显示图片引发异常

Xamarin表单Android显示图片引发异常,android,image,xamarin,xamarin.forms,resolution,Android,Image,Xamarin,Xamarin.forms,Resolution,在一个页面中显示来自图库的多张图片会引发异常。在一页上显示一张分辨率为(例如3264x2488)的照片是可行的。但是,当涉及到显示多个高分辨率的屏幕时,Android会崩溃。分辨率越高,页面上显示的内容就越少 我可以在我的ListView中看到相同的行为。ListView中的一张照片效果很好。一旦我添加了另一张照片,它就会再次崩溃 这是我的回购协议,您可以在这里找到我正在运行的Xamarin Forms应用程序: 我正在用Android 4.3调试三星Galaxy S3 如果有人能

在一个页面中显示来自图库的多张图片会引发异常。在一页上显示一张分辨率为(例如3264x2488)的照片是可行的。但是,当涉及到显示多个高分辨率的屏幕时,Android会崩溃。分辨率越高,页面上显示的内容就越少


我可以在我的ListView中看到相同的行为。ListView中的一张照片效果很好。一旦我添加了另一张照片,它就会再次崩溃


这是我的回购协议,您可以在这里找到我正在运行的Xamarin Forms应用程序:

我正在用Android 4.3调试三星Galaxy S3

如果有人能帮忙,我将不胜感激

更新:

@我是对的。我得到一个“OutOfMemoryException”


在显示图像之前,调整图像大小的最佳方法是什么?

有一篇关于Android开发者如何:


理想情况下,您可以为屏幕上未显示的每张图片释放内存以释放资源。

您可以尝试降低这些图像的分辨率吗?我猜你会得到一个记忆中的例外,这是真的。这是一个内存不足的异常。我试过一张分辨率为400x400的照片。现在我可以显示更多的图像。但当显示超过20个图像时,它仍然会崩溃。您可能需要进一步减少它们,当图像未显示在页面中时,回收机制应启动回收。在这一点上,一个页面可以容纳多少个图像以及您有多少可用内存?项目数量没有限制。用户可以添加任意数量的项目。我在哪里可以看到(从哪里获得信息)此时我有多少可用内存?如果你指的是内存-智能手机显示的内存总量为831MB。如果内存不足,我会检查内存状态。我想这可能只用于android项目。但我的麻烦在于xamarin forms项目。
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="RezepteTagebuch.Views.RecipeView">
    <...>
    <StackLayout HorizontalOptions="Fill" Orientation="Horizontal">
      <Image Source="{Binding FoodPicture}"/>
      <Image Source="{Binding DescriptionPicture}"/>
    </StackLayout>
    </...>
<StackLayout>   
  <ListView ItemsSource="{Binding Recipes}" x:Name="recipeList">    
    <...>
    <ViewCell>
      <StackLayout HorizontalOptions="StartAndExpand" Orientation="Horizontal">
            <Image WidthRequest="44" HeightRequest="44" Source="{Binding FoodPicturePath}" />              
      </StackLayout>
    </ViewCell>
    </...>
  </ListView>
</StackLayout>
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
    int reqWidth, int reqHeight) {

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(res, resId, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeResource(res, resId, options);
}