[英]How to show the last captured image from the camera without code in Image view
I am new to the Titanium Android Mobile application development. 我是Titanium Android Mobile应用程序开发的新手。
My problem is how do i load the last captured image of camera in an image view. 我的问题是如何在图像视图中加载相机的最后捕获图像。
I have a bitton called as click in one window and I have to display that image in second window. 我在一个窗口中有一个被称为“点击”的Bitton,并且必须在第二个窗口中显示该图像。
How will I achieve this , remebr no code is needed only using the Titanium android. 我将如何实现这一目标,所以仅使用Titanium android不需要代码。
Thanks 谢谢
Try this code... 试试这个代码...
Ti.Media.showCamera({
success : function(event) {
if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
// Here you can do whatever you want with the image captured from the camera
var imgView = Ti.UI.CreateImageView({
image: event.media,
width: Ti.UI.SIZE, height: Ti.UI.SIZE
});
Ti.UI.currentWindow.add(imgView); // It will be added to the centre of the window if you didn't specify top or left or ...
} else {
alert("got the wrong type back =" + event.mediaType);
}
},
cancel : function() {
alert("You have cancelled !");
},
error : function(error) {
alert("error");
},
saveToPhotoGallery : true,
allowEditing : true,
mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO]
});
You will receive the captured image data via a method of the Callback interface. 您将通过Callback接口的方法接收捕获的图像数据。 Callback interface is used to supply image data from a photo capture.
回调接口用于提供照片捕获的图像数据。
Camera.PictureCallback
onPictureTaken(byte[] data, Camera camera)
{
......
Your code
......
}
You can do whatever you want to do with image data here. 您可以在此处对图像数据做任何想做的事情。 Means you can set the image to imageview here.
意味着您可以在此处将图像设置为imageview。 You will receive data in bytes.
您将以字节为单位接收数据。 Simply convert it to drawable/bitmap and set that drawable/bitmap to the imageview.
只需将其转换为drawable / bitmap并将该drawable / bitmap设置为imageview即可。 Thats it!
而已!
For converting bytes to bitmap you can use this link : How to convert byte array to Bitmap 要将字节转换为位图,可以使用以下链接: 如何将字节数组转换为位图
Thanks for all the response ... I have solved this my own. 感谢您的所有回复...我自己解决了这个问题。
var image = event.media;
var image = event.media;
then capture the native path for the image using nativePath 然后使用nativePath捕获图像的本机路径
image.nativePath
image.nativePath
and then store this path to the application property and reuse this property using Application getString function. 然后将此路径存储到应用程序属性,并使用Application getString函数重用此属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.