Camera 如何设置快照文件的名称

Camera 如何设置快照文件的名称,camera,java-me,snapshot,Camera,Java Me,Snapshot,我正在开发一个J2ME应用程序,在我的W595s索尼爱立信手机上运行。 我的应用程序使用JSR135移动媒体API和JSR234高级多媒体补充API 我的应用程序将显示一个表单。 相机视频显示在表单的项目中。 表单有一个命令。 当用户激活命令时,应用程序将拍摄快照。 快照文件保存到记忆棒上的图片目录中 以下是表单的commandAction事件侦听器: public void commandAction(Command arg0, Displayable arg1) { m_snaps

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

我的应用程序将显示一个表单。
相机视频显示在表单的项目中。
表单有一个命令。
当用户激活命令时,应用程序将拍摄快照。
快照文件保存到记忆棒上的图片目录中

以下是表单的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);
}
我运行了两次应用程序。
图片目录在第一次运行之前未包含任何快照文件。
在每次运行期间,我执行了以下操作:

  • 我启动了命令
  • 我对以下请求权限的对话框回答“是”:
  • 是否允许应用程序读取用户数据
  • 是否允许应用程序写入用户数据
  • 是否允许应用程序读取用户数据
  • 是否允许应用程序写入用户数据
  • 是否允许应用程序使用相机拍摄
  • 是否允许应用程序读取用户数据
  • 是否允许应用程序写入用户数据
  • 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来确定文件夹中已经存在哪些文件。

    我还没有在这一特定范围的手机上尝试过,但是这个怎么样:

    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来确定文件夹中已经存在哪些文件。

    我已将播放列表添加到快照控件的播放器中。
    当拍摄停止事件发生时,我的playerUpdate方法重命名创建的快照文件。
    新名称由当前日期和时间的部分组成。
    新名称的格式为YYYYMMDD_HHMMSS.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();
                }
            }
        }
    }
    
    public void playerUpdate(播放器arg0、字符串arg1、对象arg2){
    if(arg1.equalsIgnoreCase(快照控制.快照停止)){
    FileConnection fconn=null;
    试一试{
    fconn=(文件连接)连接器。打开(“file:///e:/Picture/“+(字符串)arg2);
    现在日期=新日期();
    日历=Calendar.getInstance();
    日历。设置时间(现在);
    StringBuffer=新的StringBuffer();
    buffer.append(calendar.get(calendar.YEAR));
    int month=calendar.get(calendar.month);
    月份++;
    如果(月<10){
    buffer.append(0);
    }
    缓冲区追加(月);
    int day=calendar.get(calendar.day/u月);
    如果(第10天){
    buffer.append(0);
    }
    缓冲区追加(天);
    buffer.append(“”);
    int hour=calendar.get(calendar.hour/OF\u DAY);
    如果(小时<10){
    buffer.append(0);
    }
    缓冲区追加(小时);
    int minute=calendar.get(calendar.minute);
    如果(分钟<10){
    buffer.append(0);
    }
    缓冲区追加(分钟);
    int second=calendar.get(calendar.second);
    如果(秒<10){
    buffer.append(0);
    }
    buffer.append(第二);
    buffer.append(“.jpg”);
    重命名(buffer.toString());
    }捕获(IOE异常){
    //TODO自动生成的捕捉块
    e、 printStackTrace();
    }最后{
    试一试{
    fconn.close();
    }捕获(IOE异常){
    //TODO自动生成的捕捉块
    e、 printStackTrace();
    }
    }
    }
    }
    
    我已经在快照控件的播放器中添加了一个播放器列表器。
    当拍摄停止事件发生时,我的playerUpdate方法重命名创建的快照文件。
    新名称由当前日期和时间的部分组成。
    新名称的格式为YYYYMMDD_HHMMSS.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();
                }
            }
        }
    }
    
    public void playerUpdate(播放器arg0、字符串arg1、对象arg2){
    if(arg1.equalsIgnoreCase(快照控制.快照停止)){
    FileConnection fconn=null;
    试一试{
    fconn=(文件连接)连接器。打开(“file:///e:/Picture/“+(字符串)arg2);
    现在日期=新日期();
    日历=Calendar.getInstance();
    日历。设置时间(现在);
    StringBuffer=新的StringBuffer();
    buffer.append(calendar.get(calendar.YEAR));
    int month=calendar.get(calendar.month);
    月份++;
    如果(月<10){
    buffer.append(0);
    }
    缓冲区追加(月);
    int day=calendar.get(calendar.day/u月);
    如果(第10天){
    buffer.append(0);
    }
    缓冲区追加(天);
    buffer.append(“”);
    int hour=calendar.get(calendar.hour/OF\u DAY);
    如果(小时<10){
    buffer.append(0);