我正在開發具有相機功能的應用程序。我想將拍攝的圖像保存在我的項目文件夾中。可以請任何人幫助我。 thanx提前。如何將捕獲的圖像保存在黑莓的文件夾中?
回答
嘗試一下本作的圖像捕捉
注意:不能在資源文件夾中存儲你只能在SD卡
class screen extends MainScreen implements FieldChangeListener
{
private VideoControl vc;
private String encoding;
private Player p;
private Field viewFinder;
private BitmapField bitmapField;
private ButtonField btn;
public screen() {
btn=new ButtonField("snap",Field.FOCUSABLE);
btn.setChangeListener(this);
add(btn);
}
public void fieldChanged(Field field, int context) {
if(field==btn)
{
try{
p = Manager.createPlayer("capture://video");
p.realize();
p.prefetch();
p.start();
vc = (VideoControl) p.getControl("VideoControl");
viewFinder = (Field)vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
vc.setVisible(true);
final String imageType = "encoding=jpeg&width=640&height=480&quality=superfine";
UiApplication.getUiApplication().invokeLater(new Runnable(){
public void run(){
byte[] image = vc.getSnapshot(imageType);
FileConnection conn = (FileConnection)Connector.open("file:///store/home/user/pictures/"+System.currentTimeMillis()+".jpeg", Connector.READ_WRITE);
conn.create();
OutputStream out = conn.openOutputStream();
out.write(image);
out.flush();
out.close();
conn.close();
Bitmap image1 = Bitmap.createBitmapFromBytes(imageBytes, 0, imageBytes.length, 4);
bitmapField.setBitmap(image1);
add(bitmapField);
}
});
} catch (Exception me){
}
}
}
}
存儲更多操作請使用此 http://supportforums.blackberry.com/rim/attachments/rim/[email protected]/226/1/SnapshotSample.zip
如果您想要將圖像從相機保存到設備中,您可以使用以下代碼。
try
{
focusControl.startAutoFocus();
byte[] image = videoControl.getSnapshot(null);
String message = "Captured "+image.length+" bytes of JPG data";
debug(message);
FileConnection conn = (FileConnection)Connector.open("file:///store/home/user/pictures/"+(new Date()).getTime()+".jpg", Connector.READ_WRITE);
conn.create();
OutputStream out = conn.openOutputStream();
out.write(image);
out.flush();
out.close();
conn.close();
Dialog.alert(message);
}
catch (Exception e) {
Dialog.alert("Capture failed due to: "+e.getMessage());
}
如果你想在運行時保存在您的項目/ RES或項目/ src中的圖像,你不能做到這一點。
您可以將圖像保存在SD卡/設備中。
爲什麼要將其保存到項目源中?
bcz我想要在我的應用程序中使用該圖像。 – Hasmukh 2011-12-30 11:09:54
將圖像保存到SD卡/設備後,您可以讀取圖像並將其用於您的應用程序。這有幫助嗎? – rfsk2010 2011-12-30 11:11:03
如果將圖像保存在設備中,您可以使用它; – alishaik786 2011-12-30 11:11:35
這下面的代碼可能會幫助你:
這個添加到您想要顯示攝像機主屏幕:
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行動)方法
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;
}
- 1. 如何捕捉圖像並保存在文件夾中
- 2. 如何捕獲圖像縮略圖並將文件保存在Android中的自定義文件夾中
- 3. 如何在文件夾中保存emgu相機捕獲圖像並檢索
- 4. 如何通過HttpConnection將圖像保存到黑莓設備?
- 5. 保存後未顯示黑莓屏幕截圖圖像文件
- 6. 保存圖像從browserfield黑莓
- 7. 如何將相機圖像保存在不同的文件夾
- 8. 在android中捕獲的圖像保存
- 9. 如何下載圖像並將其保存在SD卡上的黑莓5.0
- 10. 如何保存捕獲的圖像中的文檔目錄
- 11. 如何將圖像文件保存在我的項目文件夾中?
- 12. Android:將圖像保存到文件夾
- 13. C#:將圖像保存到文件夾
- 14. 捕獲一個sceenshot並將其保存在文件夾中
- 15. 如何將捕獲的圖像保存到圖庫
- 16. Android-如何在選擇的文件夾中保存圖像
- 17. 如何將圖像從drawView保存到指定的文件夾
- 18. 如何將圖像保存到我的文件夾?
- 19. 如何使用jquery將圖像保存到文件夾中
- 20. 如何用相機捕捉圖像並保存在文件夾中
- 21. C#:捕獲多個圖像並保存在同一個文件夾中?
- 22. 如何保存在黑莓10
- 23. 如何將短信保存到黑莓收件箱中
- 24. 如何保存並刪除黑莓風暴中的位圖圖像?
- 25. 如何將圖像文件保存或移動到包含在我的php文件夾中的文件夾
- 26. 在黑莓中,如何在數據庫中存儲圖像?
- 27. 如何在Asp.net中的文件夾中保存圖像控制圖像
- 28. 如何將捕獲的圖像文件保存到data/data/<package.name>/cache?
- 29. 如何將在applet中創建的圖像保存到指定的文件夾?
- 30. 如何在增加在數據文件夾中的文件($ HOME)的黑莓10
你是什麼項目文件夾呢? – rfsk2010 2011-12-30 10:25:20
項目文件夾是指在src中存在的簡單文件夾。 – Hasmukh 2011-12-30 10:52:49