How to take a photo using Camera in Sencha App?

只谈情不闲聊 提交于 2019-12-08 08:24:23

问题


I am trying to take a picture using camera in Sencha Touch 2. Here i have one button 'Take a Picture', when i will press it, camera should start. As i am new to this sencha touch 2, i am unable to figure it out, how to do this? For this i used the below code:

Sencha Fiddle Link

Please help me. I do not want to use Phone gap.


回答1:


You have to add device folder of Sencha Library in root directory and add below code in

Ext.require('Ext.device.Camera');

and use this code for capture image using camera

Ext.device.Camera.capture({
            success: function(image) {
                imageView.setSrc(image);
            },
            quality: 75,
            width: 200,
            height: 200,
            destination: 'data'
        });



回答2:


If you want to use purely sencha, then you can check this code:

 xtype: 'button',
            handler: function(button, event) {
                Ext.device.Camera.capture({
                    source: 'camera',
                    destination: 'data',

                    success: function(imagedata) {

                        var img = Ext.getCmp('theimage');
                        img.setSrc('data:image/jpeg;base64,' +imagedata);
                    },

                    failure: function() {
                        Ext.Msg.alert('Error', 'There was an error when acquiring the picture.');
                    },
                    scope: this
                });

But if you want to use phonegap camera features, may be you have to change the code. As sencha is giving the default feature to handle the camera, i wish not to go with phonegap. Hope it will help..



来源:https://stackoverflow.com/questions/10893707/how-to-take-a-photo-using-camera-in-sencha-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!