使用此代码,我可以拍照,但在 onCreate()中,图像的名称是静态的,如“name.jpg”,但当我将其更改为新的Date()。toString()+“。jpg “它停止工作...... 请帮我根据拍照时间制作动态图像的名称。 感谢
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.picturelayout);
String imageName=new Date().toString();
path=Environment.getExternalStorageDirectory()+"/TrackMe/"+"name.jpg";
}
public void CLICK(View v)
{
File f=new File(path);
Uri myuri=Uri.fromFile(f);
Intent i =new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT, myuri);
startActivityForResult(i, 0);
}
public void back(View view){
Intent intentBack=new Intent(getApplicationContext(),SettingsActivity.class);
startActivity(intentBack);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==0)
{
Toast.makeText(getApplicationContext(), "Photo not taken",
Toast.LENGTH_LONG).show();
}
else
{
Bitmap bm = BitmapFactory.decodeFile(path);
ImageView iv=(ImageView)findViewById(R.id.trackMePicture);
iv.setImageBitmap(bm);
}
}
答案 0 :(得分:1)
生成时间戳为
SimpleDateFormat s = new SimpleDateFormat("ddhhmmss");
format = s.format(new Date());
答案 1 :(得分:0)
使用此
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
String imageName = sdf.format(new Date());
path=Environment.getExternalStorageDirectory()+"/TrackMe/"+imageName+".jpg";
答案 2 :(得分:0)
试试这个,
获取日期值,
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
使用此字符串保存
path=Environment.getExternalStorageDirectory()+"/TrackMe/"+"timeStamp.jpg"