我为我的相机活动添加了以下代码,代码工作正常,但它只在目录中创建一个图像。 我想用序列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));
}
}
答案 0 :(得分:1)
替换此行
File imagefile = new File(folder, "image.jpg");
这
String imageName = String.valueOf(System.currentTimeMillis()) + ".jpg";
File imagefile = new File(folder, imageName);