尝试调用虚拟方法';intandroid.graphics.Bitmap.getHeight()';关于空对象引用
我正在从“画廊”或“拍照”中选择图像。我的问题是,当使用相机拍照时,按下后键。我发现了错误 我的代码是尝试调用虚拟方法';intandroid.graphics.Bitmap.getHeight()';关于空对象引用,android,bitmap,camera,Android,Bitmap,Camera,我正在从“画廊”或“拍照”中选择图像。我的问题是,当使用相机拍照时,按下后键。我发现了错误 我的代码是 if (items[position].equals("Take photo")) { Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File file= getOutputMediaFile();
if (items[position].equals("Take photo")) {
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File file= getOutputMediaFile();
Uri picUri = Uri.fromFile(file);
filepath = picUri.getPath();
i.putExtra(MediaStore.EXTRA_OUTPUT,picUri);
_a.startActivityForResult(i, 1);
}
在这个UI_AddCar.ivTakenPicture中,图像视图是Piyush Gupta提供的。如果条件允许,我会更新
if(filePath != null && bitmap != null){
int height = bitmap.getHeight(), width = bitmap.getWidth();
if (height > 1280 && width > 960){
Bitmap imgbitmap = BitmapFactory.decodeFile(filePath, options);
im.setImageBitmap(imgbitmap);
im.setVisibility(View.VISIBLE);
}else {
im.setImageBitmap(bitmap);
im.setVisibility(View.VISIBLE);
}
}
您的位图为空。在下面的日志中打印位图的
height
,int height=bitmap.getHeight()Bro感谢您的解决方案我通过更改if(filePath!=null&&bitmap!=null){int height=bitmap.getHeight(),width=bitmap.getWidth();if(height>1280&&width>960)等if条件实现了这一点{
void setImage(ImageView im){
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
Bitmap bitmap = BitmapFactory.decodeFile(filePath);
if(filePath != null){
int height = bitmap.getHeight(), width = bitmap.getWidth();
if (height > 1280 && width > 960){
Bitmap imgbitmap = BitmapFactory.decodeFile(filePath, options);
im.setImageBitmap(imgbitmap);
im.setVisibility(View.VISIBLE);
} else {
im.setImageBitmap(bitmap);
im.setVisibility(View.VISIBLE);
}
}
if(filePath != null && bitmap != null){
int height = bitmap.getHeight(), width = bitmap.getWidth();
if (height > 1280 && width > 960){
Bitmap imgbitmap = BitmapFactory.decodeFile(filePath, options);
im.setImageBitmap(imgbitmap);
im.setVisibility(View.VISIBLE);
}else {
im.setImageBitmap(bitmap);
im.setVisibility(View.VISIBLE);
}
}