Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.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
无法在android studio中在我的屏幕上显示和保存捕获的图像_Android_Android Camera Intent - Fatal编程技术网

无法在android studio中在我的屏幕上显示和保存捕获的图像

无法在android studio中在我的屏幕上显示和保存捕获的图像,android,android-camera-intent,Android,Android Camera Intent,当我只显示捕获图像时,我的代码起作用;当我添加代码以将捕获的图像保存在gallery中时,代码不起作用 public class MainActivity extends Activity { private static int RESULT_LOAD_IMG = 1; String imgDecodableString; ImageView iv; Button b; @Override protected void onCreate(Bun

当我只显示捕获图像时,我的代码起作用;当我添加代码以将捕获的图像保存在gallery中时,代码不起作用

public class MainActivity extends Activity {
    private static int RESULT_LOAD_IMG = 1;
    String imgDecodableString;
    ImageView iv;
    Button b;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iv = (ImageView) findViewById(R.id.imgView);
        Button b = (Button) findViewById(R.id.buttonLoadPicture);
        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String path = Environment.getExternalStorageDirectory() + "/CameraImages/example.jpg";
                File file = new File(path);
                Uri outputFileUri = Uri.fromFile(file);
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
                startActivityForResult(intent, 1);
            }
        });
    }

    Bitmap bmp;

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (data != null && data.getExtras() != null) {
            bmp = (Bitmap) data.getExtras().get("data");

            iv.setImageBitmap(bmp);
        }

    }
}
请帮帮我,我被打昏了

编辑: 这是我的日志

12-23 12:44:07.701 8180-8180/com.prgguru.example D/dalvikvm﹕ Late-enabling CheckJNI 
12-23 12:44:07.741 8180-8180/com.prgguru.example D/ActivityThread﹕ handleBindApplication:com.prgguru.example 
12-23 12:44:07.741 8180-8180/com.prgguru.example D/ActivityThread﹕ setTargetHeapUtilization:0.25 
12-23 12:44:07.741 8180-8180/com.prgguru.example D/ActivityThread﹕ setTargetHeapMinFree:2097152 
12-23 12:44:07.751 8180-8180/com.prgguru.example D/ActivityThread﹕ setTargetHeapConcurrentStart:2097152 
12-23 12:44:07.761 8180-8180/com.prgguru.example V/HwPolicyFactory﹕ : success to get AllImpl object and return.... 
12-23 12:44:07.781 8180-8180/com.prgguru.example V/HwWidgetFactory﹕ : successes to get AllImpl object and return.... 
12-23 12:44:07.931 8180-8180/com.prgguru.example I/Adreno-EGL﹕ : EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LNX.LA.3.7.2.1_RB1.04.04.04.157.009_msm8916_32_LNX.LA.3.7.2.1_RB1__release_AU () OpenGL ES Shader Compiler Version: E031.24.02.07 Build Date: 07/30/14 Wed Local Branch: mybranch3995205 Remote Branch: quic/LNX.LA.3.7.2.1_rb1 Local Patches: NONE Reconstruct Branch: AU_LINUX_ANDROID_LNX.LA.3.7.2.1_RB1.04.04.04.157.009 + NOTHING 
12-23 12:44:07.951 8180-8180/com.prgguru.example D/OpenGLRenderer﹕ Enabling debug mode 0 
12-23 12:44:08.011 8180-8180/com.prgguru.example I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@41d32720 time:84097175 
12-23 12:44:14.891 8180-8180/com.prgguru.example V/AudioManager﹕ playSoundEffect effectType: 0 
12-23 12:44:14.891 8180-8180/com.prgguru.example V/AudioManager﹕ querySoundEffectsEnabled... 
12-23 12:44:14.891 8180-8180/com.prgguru.example D/StubController﹕ holdAndGetPermissionType permissionType:1024 uid:10095 pid:8180 
12-23 12:44:14.891 8180-8180/com.prgguru.example D/StubController﹕ addRequestCount, mRequestCount =1 mPhoneIDRequestCount: 0 mLocationRequestCount: 0 permissionType is: 1024 
12-23 12:44:14.891 8180-8180/com.prgguru.example D/StubController﹕ holdForGetPermissionSelection mRequestCount:1 
12-23 12:44:14.901 8180-8180/com.prgguru.example D/StubController﹕ beforeShowDialogCheckResult:1 
12-23 12:44:14.901 8180-8180/com.prgguru.example D/StubController﹕ minusRequestCount, mRequestCount =0 mPhoneIDRequestCount: 0 mLocationRequestCount: 0 permissionType is: 1024 
12-23  12:44:20.441 8180-8180/com.prgguru.example I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@41d32720 time:84109606 
12-23 12:44:23.131 8180-8180/com.prgguru.example I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@41d32720 time:84112293
我的XML 这是我的xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ImageView
    android:id="@+id/imgView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1" >
</ImageView>

<Button
    android:id="@+id/buttonLoadPicture"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="0"
    android:onClick="loadImagefromGallery"
    android:text="Load Picture" >
</Button>


此代码用于使用相机捕获图像,然后将其存储。如果要将图像存储到特定位置,可以进行适当的更改

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == REQUEST_CAMERA) {
                Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                assert thumbnail != null;
                thumbnail.compress(Bitmap.CompressFormat.PNG, 100, stream);

                File destination = new File(Environment.getExternalStorageDirectory(),
                        System.currentTimeMillis() + ".png");

                FileOutputStream fo;
                try {
                    destination.createNewFile();
                    fo = new FileOutputStream(destination);
                    fo.write(stream.toByteArray());
                    fo.close();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

@Sivakumar S:检查是否存在“CameraImages”目录。如果没有,那么首先创建目录。谢谢@Amit Tiwari我的图片现在存储在sd卡中,但是如果我删除“intent.putExtra(MediaStore.EXTRA_OUTPUT,outputFileUri)”,则我捕获的图片不会显示在imageview中此行表示我的图片显示在imageview中,否则功能正常,但图像不显示在imageview中。我不知道如何修复此问题,请帮助我修复此问题。你可以发布布局文件吗?我发布了布局文件,如果不使用MediaStore.EXTRA_输出,实际上图片正在显示,但我需要此命令来存储我的图片。。。请帮我看看答案。它显示了如何正确保存图像,并获得完整大小的图像,而不是缩略图。