Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.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
Java 捕获图像将其显示在ImageView上,并以不同的序列号将图像保存在SD卡中_Java_Android_Android Studio - Fatal编程技术网

Java 捕获图像将其显示在ImageView上,并以不同的序列号将图像保存在SD卡中

Java 捕获图像将其显示在ImageView上,并以不同的序列号将图像保存在SD卡中,java,android,android-studio,Java,Android,Android Studio,我已经为我的相机活动添加了以下代码,代码运行良好,但它只在目录中创建一个图像。 我想用sequence image.1.jpg、image.2.jpg等添加更多图像。 我该怎么做呢。 请建议 public class camera extends AppCompatActivity { ImageButton image_button; ImageView image_view; static final int CAMER

我已经为我的相机活动添加了以下代码,代码运行良好,但它只在目录中创建一个图像。 我想用sequence image.1.jpg、image.2.jpg等添加更多图像。 我该怎么做呢。 请建议

public class camera extends AppCompatActivity {
            ImageButton image_button;
            ImageView image_view;
            static final int CAMERA_REQUEST = 1;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_camera);
                image_button= (ImageButton)findViewById(R.id.imageButton);
                image_view= (ImageView)findViewById(R.id.imageView8);
                image_button.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                        File file = getFile();
                        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                        startActivityForResult(intent, CAMERA_REQUEST);
                    }
                });

            }
            private File getFile()
            {
                File folder = new File("sdcard/3D_TRY");
                if (!folder.exists())
                {
                    folder.mkdir();
                }

                File imagefile = new File(folder,"image.jpg");
                return imagefile;
            }
        @Override
            protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                String path = "sdcard/3D_TRY/image.jpg";
                image_view.setImageDrawable(Drawable.createFromPath(path));
            }
        }
更换这条线

File imagefile = new File(folder, "image.jpg");

String imageName = String.valueOf(System.currentTimeMillis()) + ".jpg";
File imagefile = new File(folder, imageName);