Android 在SD卡上存储带有日期时间戳的图像

Android 在SD卡上存储带有日期时间戳的图像,android,image,datetime,android-sdcard,Android,Image,Datetime,Android Sdcard,我已经编写了将位图图像存储在SD卡中的代码,但我想将其与日期时间戳一起存储。如何操作 bmp = processFrame(mCamera); String i1=bmp.toString(); String root = Environment.getExternalStorageDirectory().toString(); File myDir = new File(root + "/saved

我已经编写了将位图图像存储在SD卡中的代码,但我想将其与日期时间戳一起存储。如何操作

bmp = processFrame(mCamera);
                String i1=bmp.toString();
                String root = Environment.getExternalStorageDirectory().toString();
                File myDir = new File(root + "/saved_images");    
                    myDir.mkdirs();
                    Random generator = new Random();
                    int n = 10000;
                    n = generator.nextInt(n);
                    String fname = "Image-"+ n +".jpg";
                    File file = new File (myDir, fname);
                    if (file.exists ()) file.delete (); 
                    try {
                           FileOutputStream out = new FileOutputStream(file);
                           bmp.compress(Bitmap.CompressFormat.JPEG, 90, out);
                           out.flush();
                           out.close();

                    } catch (Exception e) {
                           e.printStackTrace();
                    }
用这个

String fname = "Image-"+ n +System.currentTimeMillis() +".jpg";
而不是

String fname = "Image-"+ n +".jpg";
试试这个:

String getCurrentDate() {
        Calendar c = Calendar.getInstance();
        String Month = "";
        switch (c.get(Calendar.MONTH)) {
        case 0:
              Month = "Jan";
              break;
        case 1:
              Month = "Feb";
              break;
        case 2:
              Month = "Mar";
              break;
        case 3:
              Month = "Apr";
              break;
        case 4:
              Month = "May";
              break;
        case 5:
              Month = "June";
              break;
        case 6:
              Month = "July";
              break;
        case 7:
              Month = "Aug";
              break;
        case 8:
              Month = "Sep";
              break;
        case 9:
              Month = "Oct";
              break;
        case 10:
              Month = "Nov";
              break;
        case 11:
              Month = "Dec";
              break;
        default:
              break;
        }
        int ampm = c.get(Calendar.AM_PM);
        String amorpm = "";
        if (ampm == 1) {
              amorpm = "PM";
        } else {
              amorpm = "AM";
        }
        String date = c.get(Calendar.DAY_OF_MONTH) + "/" + Month + "/"
                    + c.get(Calendar.YEAR) + " " + c.get(Calendar.HOUR) + ":"
                    + c.get(Calendar.MINUTE) + " " + amorpm;
        // int Day = c.get(Calendar.DAY_OF_MONTH);
        // int month = c.get(Calendar.MONTH);
        return date;
  }

SimpleDataFormat sdf=新的SimpleDataFormat(“yyyy-MM-dd HH:MM:ss”);字符串dateTime=sdf.format(Calendar.getInstance().getTime());通过这段代码,我得到了日期时间,但如何将其存储到Images而不是字符串fname=“Image-”+n+System.currentTimeMillis()+“.jpg”;使用字符串fname=“Image-”+n+getCurrentDate()+“.jpg”;当我这样做的时候,改变了形象,没有得到任何提示,你敢在日志中得到任何警告吗?我想我得到了问题。文件名不应包含或/或*等,请检查要获取的文件名