I am developing android application, In my application I want to take photo from camera and set as image in image view. my code looks like
var img_view = Titanium.UI.createImageView({
image: '/images/default.png',
height: '100%',
width: '100%',
}); win.add(img_view);
photo_camera_view = Ti.UI.createView(
{
height: '20dp',
backgroundColor:'#fff'
}); win.add(photo_camera_view);
photo_camera_view.addEventListener('click', function(e)
{
Titanium.Media.showCamera(
{
success:function(event)
{
img_view.image = event.media;
},
cancel:function()
{
},
error:function(error)
{
// create alert
},
});
});
my need is take a pic from camera and set image: 'photo from camera' in img_view. In Android, when I execute Ti.Media.showCamera, after successfully taking a picture and hitting "OK" in the app, the application will restart. I am using titanium sdk 2.0.1 and testing it on android device with android version 2.2. Need Help ..... Thank you........
You need to set the image in the success event like below.
img_view.setImage(event.media);
You just cannot assign the image to the property. The image view has to be redrawn with new image. And try it in Android 4.0 emulator as the below versions had issues with camera.
Related
i am using react-native-image-crop-picker library as camera but when i open camera getting chooser option to select any one camera app i want to directly open default camera without showing chooser options from react native
You can use this:
ImagePicker.openCamera({
width: 300,
height: 400,
cropping: true,
}).then(image => {
console.log(image);
});
You can directly invoke the function provided by react-native-image-crop
it is called openCamera for camera opening
you can use it as the following
ImagePicker.openCamera({
...your camera config
}).then(image => {
console.log(image);
});
How to open only default android camera in cordova:
In my phone tow camera one is default camera and second is Beautify aap. I want to open only my default camera only by using cordova.
please use following plugin
cordova plugin add org.apache.cordova.camera
this function will open camera app,
$scope.takePicture = function (options) {
var options = {
quality : 75,
targetWidth: 200,
targetHeight: 200,
sourceType: 1
};
Camera.getPicture(options).then(function(imageData) {
$scope.picture = imageData;;
}, function(err) {
console.log(err);
});
};
if above function is opening Beautify camera app,then you have selected it as default camera app,please check in phone settings.
Clear defaults from Beautify camera app
For references:
Tutorial 1
Tutorial 2
I am trying navigator.MediaDevices.getUserMedia() webrtc to switch the device camera during the call. This functionality is working fine on the desktop browser but on mozilla android it is not working.
Here is my code that i am using .
var front=false;
var myConstraints = { video: { facingMode: (front? "user" : "environment")} };
navigator.mediaDevices.getUserMedia(myConstraints).then(function(stream) {
}
any idea about this??
Phone hardware typically doesn't allow opening both the front and back camera at the same time. Change your code to stop() the existing stream before getting the other camera.
See my answer to a similar question for a working example.
use the last version of adapter.js and see if NotReadableerror is happening, it seems that Chrome for android cannot release front camera hardware to switch to rear by using stream.getVideoTracks()[0].stop(); I think it could be a bug
Webcam.set({
width: 490,
height: 450,
image_format: 'jpeg',
jpeg_quality: 90,
constraints: {
facingMode: {
exact: 'environment'
}
}
});
This code is working for all browsers.
constraints: {facingMode: { exact: 'environment' }}
Above line is responsible to open rear camera, set constraints : null to open front camera. you can also adjust this code by implementing "switch camera" button method
I have an image view and try to load remote image but it's can not show up.
I'm already search and try any suggestion on this forum but not work. I'm using SDK 3.2.2 on Mac OS X Maverick
My code is like here, and it's running good on iOS.
var iconImage = Ti.UI.createImageView({
width:40,
height:40,
left:5,
hires:true,
defaultImage:'/images/default.jpg',
image:urltoimage
});
sample image
this is a bug or something wrong with my code?any suggestion how to do remote image? Please help..
Use this
exports.LoadRemoteImage = function (obj,url) {
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function()
{
Ti.API.info('image data='+this.responseData);
obj.image=this.responseData;
};
// open the client
xhr.open('GET',url);
// send the data
xhr.send();
};
save on new file and named "ImageLoader.js"
I'm forget where I found that code, but I'm used that to handle any image from internet.
usage:
var ImageLoader = require('ImageLoader');
var imageView = Ti.UI.createImageView({
width:100,
height:100
})
ImageLoader.LoadRemoteImage(imageView,"http://i1314.photobucket.com/albums/t567/vademahendra/sightseeing_zpsd91fa049.png?t=1401680320");
I hope this can help you
I've run application with this code:
var urltoimage = 'http://i1314.photobucket.com/albums/t567/vademahendra/sightseeing_zpsd91fa049.png?t=1401680320';
var win = Ti.UI.createWindow();
var iconImage = Ti.UI.createImageView({
width: 40,
height: 40,
left: 5,
hires: true,
defaultImage: '/images/default.jpg',
image: urltoimage
});
win.add(iconImage);
win.open();
All worked properly, so the issue has to be on your device or simulator.
Check network connection and if airplane mode is enabled.
Does it show up on the device and just not on the emulator, or does it not show up at all?
Sometimes Android can be temperamental about remote images. CDNs usually work really well which is probably why daniula's code worked. Things to try are:
Change the pixel dimensions of your remote image to be smaller - test
Change the image file size of course using different compressions - test
Try different file types
Try using the same image url daniula used to see narrow it down to the image or the code: if the images shows up, then it's a problem with the serving of the images; if the image does not show, it may be an issue with your code.
I'm working on Titanium 2.1.3 and deploying for both iOS and Android.
I'm having trouble displaying images on ImageView on Android in a TableView, if I do something like clicking on the search bar and show the keyboard then the images are shown or if I scroll the TableView the images appear and disappear with no apparent reason. It seems that unless I do something that forces a layout refresh on the TableView, the images aren't rendered.
The images are being loaded the same way in both Android and iOS, which is like this:
var itemIconHolder = Titanium.UI.createView({
width : '100dp',
left : '55dp',
height : "100%"
});
var itemIcon = Titanium.UI.createImageView({
left : '0dp',
height : '100%',
});
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "thumb-" + filename);
itemIcon.image = f;
itemIconHolder.add(itemIcon);
This problem doesn't happen in iOS, on iOS devices/simulator the behaviour is normal and flawless, but on Android devices/emulator it happens.
Do I have to load the images differently in Android? Am I missing something? I hope someone could help me in this one.
Thanks in advance.
EDIT
I tried these approaches:
itemIcon.image = f.read();
and
itemIcon.image = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "thumb-" + filename);
but the images still aren't rendered until I make something that causes the TableView to refresh in some way.
I found a workaround for this particular issue on Android.
Since it takes a layout refresh for the images to be rendered properly, what I did was to animate the table, moving it 1dp in a direction and at the completition of said animation I animated it again to return it to its original position. This is the code I used:
var table_bottom = '-1dp'
var tableAnimation = Ti.UI.createAnimation({
bottom : table_bottom,
duration : 100
});
tableAnimation.addEventListener('complete', function(e){
var table_bottom = '50dp';
if (osname === 'android')
{
table_bottom = '0dp'
}
table.animate({
bottom : table_bottom,
duration : 100
});
});
I've encountered this kind of problem with both Titanium SDK 2.1.3 and Titanium 3.0.