Android 检查位图是否为空
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10701023/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
check if bitmap is null
提问by Rizwan Mumtaz
Bitmap bmp;
bmp = (Android.Graphics.Bitmap)data.Extras.Get("data");
CallToFunction (bmp);
Calling a function with Bitmap.
使用位图调用函数。
private void CallToFunction(Bitmap bmp)
{
if(bmp)
{
}
}
回答by Blackbelt
private void CallToFunction(Bitmap bmp)
{
if (bmp != null)
{
}
}
回答by Ryan
Not too much to go on here however I suspect that you are getting a null reference exception when you do an implicit conversion to the bitmap where "data" could be null?
这里没有太多内容,但是我怀疑当您对“数据”可能为空的位图进行隐式转换时,您会收到空引用异常?
Check that data is not empty before converting to a bitmap.
在转换为位图之前检查数据是否为空。
var data = data.Extras.Get("data");
if(data != null){
CallToFunction ((Android.Graphics.Bitmap)data);
}
回答by bhavindesai
You can check via
您可以通过
if(data.Extras.Get("data")!=null && data.Extras.Get("data") instanceOf Bitmap){
CallToFunction ((Android.Graphics.Bitmap)data.Extras.Get("data"));
}
回答by Sumant
You can use the following it will check if bitmap is not not null only then that method will be called other it will not called that method.
您可以使用以下方法检查位图是否不为空,然后才会调用该方法,否则不会调用该方法。
Bitmap bmp;
bmp = (Android.Graphics.Bitmap)data.Extras.Get("data");
if (bmp != null)
{
CallToFunction (bmp);
}