gpt4 book ai didi

java - 抓取图片在ImageView上显示,并保存在不同序列号的SD卡中

转载 作者:行者123 更新时间:2023-11-30 01:36:10 26 4
gpt4 key购买 nike

我为我的相机 Activity 添加了以下代码,该代码工作正常,但它只在目录中创建一个图像。我想用序列 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);

关于java - 抓取图片在ImageView上显示,并保存在不同序列号的SD卡中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35083414/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com