0

我已经编写了将位图图像存储在 sdcard 中的代码,但我想将它与日期时间戳一起存储。怎么做?

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();
                    }
4

1 回答 1

1

用这个

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;
  }
于 2012-09-10T07:50:54.620 回答