使用 BitmapFactory.DecodeResourceAsync Xamarin 在 Marshmallow 中加载图像失败
Loading image failed in Marshmallow using BitmapFactory.DecodeResourceAsync Xamarin
我正在使用此代码加载图像
async Task<BitmapFactory.Options> GetBitmapOptionsOfImageAsync()
{
BitmapFactory.Options options = new BitmapFactory.Options
{
InJustDecodeBounds = true
};
// The result will be null because InJustDecodeBounds == true.
Bitmap result= await BitmapFactory.DecodeResourceAsync(Resources, Resource.Drawable.samoyed, options);
int imageHeight = options.OutHeight;
int imageWidth = options.OutWidth;
_originalDimensions.Text = string.Format("Original Size= {0}x{1}", imageWidth, imageHeight);
return options;
}
https://developer.xamarin.com/recipes/android/resources/general/load_large_bitmaps_efficiently/
除了 Marshmallow options
returns null 外,它工作正常。我错过了什么?
以防有人遇到同样的问题。我发现只有在使用 Visual Studio 模拟器和 API 23 (Marshmallow) 进行调试时才会出现此问题。不过我还没有用其他模拟器测试过它。
当我使用物理设备调试时,没有出现问题。
请务必 select Android 6.0 (Marshmallow)
for Compile using Android version:
and Target Android version:
in Application properties
.
编译Release
版本时,确保将Android Options
下的Linker properties
设置为Sdk Assemblies Only
我正在使用此代码加载图像
async Task<BitmapFactory.Options> GetBitmapOptionsOfImageAsync()
{
BitmapFactory.Options options = new BitmapFactory.Options
{
InJustDecodeBounds = true
};
// The result will be null because InJustDecodeBounds == true.
Bitmap result= await BitmapFactory.DecodeResourceAsync(Resources, Resource.Drawable.samoyed, options);
int imageHeight = options.OutHeight;
int imageWidth = options.OutWidth;
_originalDimensions.Text = string.Format("Original Size= {0}x{1}", imageWidth, imageHeight);
return options;
}
https://developer.xamarin.com/recipes/android/resources/general/load_large_bitmaps_efficiently/
除了 Marshmallow options
returns null 外,它工作正常。我错过了什么?
以防有人遇到同样的问题。我发现只有在使用 Visual Studio 模拟器和 API 23 (Marshmallow) 进行调试时才会出现此问题。不过我还没有用其他模拟器测试过它。
当我使用物理设备调试时,没有出现问题。
请务必 select Android 6.0 (Marshmallow)
for Compile using Android version:
and Target Android version:
in Application properties
.
编译Release
版本时,确保将Android Options
下的Linker properties
设置为Sdk Assemblies Only