blackberry - 如何将捕获的图像保存在黑莓的文件夹中?

标签 blackberry

我正在开发具有相机功能的应用程序。我想将捕获的图像保存在我的项目文件夹中。有人可以帮助我吗? 提前致谢。

最佳答案

This below code may help you:

将此添加到您想要显示相机的主屏幕:

captureImage=new MenuItem("Capture Images",10,100) 
{           
    public void run() 
    {
        synchronized (Application.getEventLock()) 
        {
            captureImage();
        }               
    }
};          
addMenuItem(captureImage);

captureImage()方法的代码是:

private void captureImage() 
{
    try 
    {
        player = javax.microedition.media.Manager.createPlayer("capture://video?encoding=jpeg&width=1024&height=768");
        player.realize();
        _videoControl = (VideoControl) player.getControl("VideoControl");

        if (_videoControl != null)
        {
            Field videoField = (Field) _videoControl.initDisplayMode (VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
            _videoControl.setDisplayFullScreen(true);
            _videoControl.setVisible(true);
            player.start();

            if(videoField != null)
            {
                add(videoField);
            }
        } 
    }
    catch(Exception e)
    {
        if(player!=null)
        {
            player.close();
        }
        Dialog.alert(e.toString());
    }       
}

下面的代码是将图像保存到SD卡或设备卡中。重写invokeAction(int action)方法

protected boolean invokeAction(int action)
{
    boolean handled = super.invokeAction(action); 

    if(SdcardTest.SdcardAvailabulity())//I am checking here that the sdcard is there of or not.....?    
    {
          //PATH = "file:///SDCard/BlackBerry/pictures/"+"Image_"+System.currentTimeMillis()+".jpg"; 
          PATH = System.getProperty("fileconn.dir.memorycard.photos")+"Image_"+System.currentTimeMillis()+".jpg";//here "str" having the current Date and Time;
    }            
    else 
    {
        PATH = System.getProperty("fileconn.dir.photos")+"Image_"+System.currentTimeMillis()+".jpg"; 
    }
    if(!handled)
    {
        if(action == ACTION_INVOKE)
        {   
            try
            {                      
                byte[] rawImage = _videoControl.getSnapshot(null);
                fileconn=(FileConnection)Connector.open(PATH);
                if(fileconn.exists())
                {
                    fileconn.delete();
                }
                fileconn.create();
                OutputStream os=fileconn.openOutputStream();
                os.write(rawImage);
                fileconn.close();
                os.close();
                Status.show("Image is Captured",200);
                if(player!=null)
                    player.close();                                       
            }
            catch(Exception e)
            {
                if(player!=null)
                {
                    player.close();
                }
                if(fileconn!=null)
                {
                    try 
                    {
                        fileconn.close();
                    } 
                    catch (IOException e1) 
                    { 
                               //if the action is other than click the trackwheel(means go to the menu options) then we do nothing;
                    }
                }                      
            }
        }
    }           
    return handled;                
}

关于blackberry - 如何将捕获的图像保存在黑莓的文件夹中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8678365/

相关文章:

pdf - 在黑莓上渲染 PDF?

java - 带有黑莓路线的谷歌地图

java - 将其他音频静音

html - 如何在我的移动网站上创建一个链接以使 Blackberry 调用电话?

AJAX XML 无法在带有 Web-Works 或 Phonegap 的 BlackBerry 上运行

黑莓 slider

blackberry - 有没有办法在黑莓Java应用程序中使用Google Analytics(分析)?

java - 以编程方式调用黑莓中的默认媒体播放器?

blackberry - 5 MB 对于 BlackBerry 应用程序来说太大了吗?

java - 编辑字段奇怪的高度