Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.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
尝试调用虚拟方法';intandroid.graphics.Bitmap.getHeight()';关于空对象引用_Android_Bitmap_Camera - Fatal编程技术网

尝试调用虚拟方法';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);
            }
     }