从位图中的 Drawable 文件夹中获取图像
Get image from Drawable folder in bitmap
如何从 BitmapFactory.DecodeResource 的可绘制文件夹中获取图像。
我试过了。
img 名称图像保存在 drawable 文件夹中然后这个
Bitmap originalImage = BitmapFactory.DecodeResource(Resource.Drawable.img,0);
但是它产生了一个错误
"Can not convert from int to Android.Content.Res.Resources"
我能够为位图解码资源获取可绘制图像。
我使用了这个代码。
string imagefileName = "imgimge.png";
// Remove the file extention from the image filename
imagefileName = imagefileName.Replace(".jpg", "").Replace(".png", "");
// Retrieving the local Resource ID from the name
int id = (int)typeof(Resource.Drawable).GetField(imagefileName).GetValue(null);
// Converting Drawable Resource to Bitmap
var originalImage = BitmapFactory.DecodeResource(Xamarin.Forms.Forms.Context.Resources, id);
位图图像 = BitmapFactory.DecodeResource(this.Resources,Resource.Drawable.blankImage);
当前上下文的第一个参数 returns 资源,然后是您的图像资源 link(应位于 'Resource' 文件夹中)
如何从 BitmapFactory.DecodeResource 的可绘制文件夹中获取图像。 我试过了。
img 名称图像保存在 drawable 文件夹中然后这个
Bitmap originalImage = BitmapFactory.DecodeResource(Resource.Drawable.img,0);
但是它产生了一个错误
"Can not convert from int to Android.Content.Res.Resources"
我能够为位图解码资源获取可绘制图像。 我使用了这个代码。
string imagefileName = "imgimge.png";
// Remove the file extention from the image filename
imagefileName = imagefileName.Replace(".jpg", "").Replace(".png", "");
// Retrieving the local Resource ID from the name
int id = (int)typeof(Resource.Drawable).GetField(imagefileName).GetValue(null);
// Converting Drawable Resource to Bitmap
var originalImage = BitmapFactory.DecodeResource(Xamarin.Forms.Forms.Context.Resources, id);
位图图像 = BitmapFactory.DecodeResource(this.Resources,Resource.Drawable.blankImage);
当前上下文的第一个参数 returns 资源,然后是您的图像资源 link(应位于 'Resource' 文件夹中)