设置快照文件的名称



我正在开发一个运行在我的W595s索尼爱立信手机上的J2ME应用程序。
我的应用程序使用JSR 135移动媒体API和JSR 234高级多媒体补充API。

我的应用程序显示一个表单。
摄像机视频显示在窗体的项中。
表单有一个命令。
当用户激活该命令时,应用程序将获取快照。
快照文件保存到记忆棒上的Picture目录

下面是Form的commandAction事件监听器:
public void commandAction(Command arg0, Displayable arg1) {
    m_snapshotControl.setDirectory("e:/Picture");
    m_snapshotControl.setFilePrefix("AC");
    m_snapshotControl.setFileSuffix(".JPG");
    int[]resolutions = m_cameraControl.getSupportedStillResolutions();
    int maxValue = (resolutions.length / 2) - 1;
    m_cameraControl.setStillResolution(maxValue);
    m_snapshotControl.start(1);
}

我运行了2次程序。
在第一次运行之前,Picture目录不包含任何快照文件。
每次运行时,我执行以下操作:

    我激活了命令
  1. 我对以下权利请求对话回答是:
    1. 允许应用程序读取用户数据?
    2. 允许应用程序写入用户数据?
    3. 允许应用程序读取用户数据?
    4. 允许应用程序写入用户数据?
    5. 允许应用程序使用相机拍摄?
    6. 允许应用程序读取用户数据?
    7. 允许应用程序写入用户数据?

第一次运行后创建了AC0000.jpg快照文件。
第二次运行后,AC0000.jpg图片文件被替换。

我不希望我的应用程序替换过去运行时拍摄的快照。
如何在快照前设置快照文件名?
是否可以在前缀和后缀之间设置字符串?

如有任何帮助,不胜感激

我还没有在这个特定的手机范围内试过,但是这个如何:

private int iSnapshotCounter = 0;
public void commandAction(Command arg0, Displayable arg1) {
    m_snapshotControl.setDirectory("e:/Picture");
    m_snapshotControl.setFilePrefix("AC");
    m_snapshotControl.setFileSuffix( (++iSnapshotCounter) + ".JPG");
    int[]resolutions = m_cameraControl.getSupportedStillResolutions();
    int maxValue = (resolutions.length / 2) - 1;
    m_cameraControl.setStillResolution(maxValue);
    m_snapshotControl.start(1);
}

如果可以,您可以决定在文件名中包含日期和时间(例如,到第二个)。

当然,如果setFileSuffix()不允许您指定多于一个文件扩展名,您可以尝试对前缀字符串使用相同的技巧。

您可能还需要使用JSR-75来找出文件夹中已经存在的文件

我已经添加了一个PlayerListener到SnapshotControl的播放器。
我的playerUpdate方法在SHOOTING_STOPPED事件发生时重命名创建的快照文件。
新名称由当前日期和时间的部分组成。
新名称的格式为"yyyymmdd_hmmss .jpg"。
下面是playerUpdate方法:

public void playerUpdate(Player arg0, String arg1, Object arg2) {
    if (arg1.equalsIgnoreCase(SnapshotControl.SHOOTING_STOPPED)) {
        FileConnection fconn = null;
        try {
            fconn = (FileConnection)Connector.open("file:///e:/Picture/" + (String)arg2);
            Date now = new Date();
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(now);
            StringBuffer buffer = new StringBuffer();
            buffer.append(calendar.get(Calendar.YEAR));
            int month = calendar.get(Calendar.MONTH);
            month++;
            if (month < 10) {
                buffer.append(0);
            }
            buffer.append(month);
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            if (day < 10) {
                buffer.append(0);
            }
            buffer.append(day);
            buffer.append("_");
            int hour = calendar.get(Calendar.HOUR_OF_DAY);
            if (hour < 10) {
                buffer.append(0);
            }
            buffer.append(hour);
            int minute = calendar.get(Calendar.MINUTE);
            if (minute < 10) {
                buffer.append(0);
            }
            buffer.append(minute);
            int second = calendar.get(Calendar.SECOND);
            if (second < 10) {
                buffer.append(0);
            }
            buffer.append(second);
            buffer.append(".jpg");
            fconn.rename(buffer.toString());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            try {
                fconn.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}

最新更新