我正在使用 Titanium Appcelerator 创建一个 iPhone 应用程序。对于其中一个选项卡,我想包括一个相机。当我单击相机图像时,我希望应用程序:
- 打开相机拍照
- 询问用户是否想再拍一张照片
- 然后再次打开相机是
- (环形)
- 将图像(本地保存)放入数组中
- 返回键!
我似乎无法在任何地方找到相机功能。
我正在使用 Titanium Appcelerator 创建一个 iPhone 应用程序。对于其中一个选项卡,我想包括一个相机。当我单击相机图像时,我希望应用程序:
我似乎无法在任何地方找到相机功能。
此链接提供了一个简短的示例,但建议查看厨房水槽演示应用程序,厨房水槽有一个几乎所有内容的示例。
var win = Titanium.UI.createWindow({
title:"Using the Camera and Video",
backgroundColor:"#FFFFFF"
});
var button = Titanium.UI.createButton({
title:"Use camera",
width:180,
height:48,
bottom: 12,
zIndex:2
});
button.addEventListener("click", function(e){
//Open the photo gallery
Titanium.Media.showCamera({
//function to call upon successful load of the gallery
success:function(e){
if(e.mediaType === Titanium.Media.MEDIA_TYPE_PHOTO){
//e.media represents the photo or video
var imageView = Titanium.UI.createImageView({
image:e.media,
width:320,
height:480,
top:12,
zIndex:1
});
win.add(imageView);
}else if(e.mediaType === Titanium.Media.MEDIA_TYPE_VIDEO){
var w = Titanium.UI.createWindow({
title:"New Video",
backgroundColor:"#000000"
});
var videoPlayer = Titanium.Media.createVideoPlayer({
media:e.media,
backgroundColor:"#FFFFFF",
//movieControlMode:Titanium.Media.VIDEO_CONTROL_DEFAULT,
/*other values
* Titanium.Media.VIDEO_CONTROL_EMBEDDED
* Titanium.Media.VIDEO_CONTROL_FULLSCREEN
* Titanium.Media.VIDEO_CONTROL_HIDDEN
* Titanium.Media.VIDEO_CONTROL_NONE
*/
//movieControlStyle:Titanium.Media.VIDEO_CONTROL_FULLSCREEN,
//scalingMode:Titanium.Media.VIDEO_SCALING_ASPECT_FIT
/*other values
* Titanium.Media.VIDEO_SCALING_ASPECT_FILL
* Titanium.Media.VIDEO_SCALING_MODE_FILL
* Titanium.Media.VIDEO_SCALING_NONE
*/
});
w.add(videoPlayer);
videoPlayer.addEventListener("complete", function(e){
w.remove(videoPlayer);
videoPlayer = null;
w.close();
});
w.open({modal:true});
}
},
error:function(e){
alert("There was an error");
},
cancel:function(e){
alert("The event was cancelled");
},
//Allow editing of media before success
allowEditing:true,
saveToPhotoGallery:true,
//Media types to allow
mediaTypes:[Titanium.Media.MEDIA_TYPE_PHOTO,Titanium.Media.MEDIA_TYPE_VIDEO],
//The other is Titanium.Media.MEDIA_TYPE_VIDEO,
//If recording video, you can set the quality to record at
videoQuality:Titanium.Media.QUALITY_HIGH
/*other possible values for this property are
* Titanium.Media.QUALITY_MEDIUM
* Titanium.Media.QUALITY_LOW
*/
});
});
Titanium.App.addEventListener('camera_button', function(){
Titanium.Media.takePicture();
});
win.add(button);
win.open();