![](/img/trans.png)
[英]How to take photo from camera and add photo gallery in android application?
[英]How to open photo gallery by clicking a button from a camera overlay?
我正在使用Titanium SDK 3.1.2,並為iOS和Android進行部署。 您可以在此處找到我的疊加層的代碼。 我這樣做是因為代碼很大,並且希望我的問題清晰明了。 我正在嘗試使用以下功能為相機創建自己的疊加層:拍照。 顯示攝像機。 打開畫廊。 關閉相機。 我可以關閉相機並拍照,但無法打開照片庫。 我的galleryButton有一個singletap事件,如下所示:
galleryButton.addEventListener("singletap", function(e){
openKineduPhotoGallery();
Ti.Media.hideCamera();
});
但是,當我這樣做時什么也沒有發生,之后我就無法關閉相機或拍照。 如果我嘗試拍照,則會出現以下錯誤:
Script Error {
backtrace = "#0 () at file://localhost/var/mobile/Applications/79D9256C-7782-4323-A371-1AD45B37D037/Full.app/ui/common/GenericWindow.js:1\n#1 () at file://localhost/var/mobile/Applications/79D9256C-7782-4323-A371-1AD45B37D037/Full.app/ui/common/CreateMoment.js:1";
line = 1;
message = "'null' is not an object (evaluating 'o.type')";
name = TypeError;
sourceId = 81147840;
sourceURL = "file://localhost/var/mobile/Applications/79D9256C-7782-4323-A371-1AD45B37D037/Full.app/ui/common/GenericWindow.js";
}
我無法弄清楚是什么對象使null出現。 我嘗試交換調用方法的順序,使其看起來像這樣:
galleryButton.addEventListener("singletap", function(e){
Ti.Media.hideCamera();
openKineduPhotoGallery();
});
但這只是隱藏了相機,根本沒有顯示圖庫,而且我在iOS中收到以下警告:
Nov 6 18:37:20 Nenvo-iPod Full[3240] <Warning>: *** Assertion failure in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:], /SourceCache/UIKit/UIKit-2380.17/UIWindowController.m:211
Nov 6 18:37:20 Nenvo-iPod Full[3240] <Warning>: Warning: Attempt to dismiss from view controller <UIImagePickerController: 0x1e5e17a0> while a presentation or dismiss is in progress!
我以為這是hideCamera方法的錯誤,所以我對此進行了評論,但這只是觸發了showCamera方法上的錯誤函數,並且我得到了這樣的JSON錯誤對象:
{
"type": "error",
"code": 1,
"source": [object MediaModule],
"success": false
}
我試圖對MediaModule進行字符串化,但它只是返回了一個空對象。 甚至有可能從攝影機疊加層打開圖庫嗎? 我有什么選擇? 我正在嘗試實現類似於instagram拍照,錄制視頻並從畫廊中選擇圖片的工作流程。
回答以下問題的方法實際上是當您調用hideCamera並打開PhotoGallery,然后將兩者都打開為模態窗口,因此我們需要在幾秒鍾的摩擦后調用openKineduPhotoGallery函數。
galleryButton.addEventListener("singletap", function(e){
Ti.Media.hideCamera();
openKineduPhotoGallery();
});
因此,您應該嘗試以下代碼。
galleryButton.addEventListener("singletap", function(e){
Ti.Media.hideCamera();
setTimeout(function(){
openKineduPhotoGallery();
},500);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.