Titanium JIRA Archive
Appcelerator Community (AC)

[AC-745] Camera preview is different to taken image on Android with overlay

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionDuplicate
Resolution Date2015-09-29T01:28:04.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
LabelsAndroid, Camera, Overlay, TCSupportTriage
ReporterOsian Evans
AssigneeShak Hossain
Created2014-12-10T09:47:53.000+0000
Updated2016-03-08T07:37:00.000+0000

Description

When using an overlay with Ti.Media.showCamera() on Android, the resulting preview shows a zoomed in version of the final picture that is taken. On taking the photo, the actual photo is displayed for a moment within the preview view, and it is visibly different.
function ModuleConstructor(_params) {
    var self = Ti.UI.createWindow();
    var cameraOverlay = Titanium.UI.createView({});
 
    var cameraOverlayButton = Titanium.UI.createImageView({
        bottom: 10,
        image: '/images/camera_btn.png',
    });
    cameraOverlay.add(cameraOverlayButton);
 
    cameraOverlayButton.addEventListener('click', function(e){
        Ti.Media.takePicture();
    });
 
    self.addEventListener("postlayout", postlayoutHandler);
    function postlayoutHandler(e) {
        self.removeEventListener("postlayout", postlayoutHandler);
        Titanium.Media.showCamera({
            overlay: cameraOverlay,
            showControls: false,
            success: function(e) {
                  Ti.API.info('# SUCCESS : '+e.success);
                  ...code etc...
            },
            cancel: function(e) {
                  Ti.API.info('# CANCEL : '+e.error);
                  ...code etc...
            },
            error: function(e) {
                  Ti.API.info('# ERROR : '+ e.code +' : '+ e.error);
                  ...code etc...
            },
            mediaTypes:Ti.Media.MEDIA_TYPE_PHOTO,
        });
    }
    return self;
};
 
module.exports = ModuleConstructor;

Attachments

FileDateSize
motog2_640.mov2015-07-06T08:21:30.000+00001083517
nexus4_640.mov2015-07-06T08:21:35.000+00001720601

Comments

  1. Osian Evans 2014-12-15

    Were you able to reproduce the issue? Do you need additional information from me?
  2. Osian Evans 2014-12-17

    I would really appreciate a response as to whether this is a bug, and if there is a workaround, or a pending fix. I realise that a fix may not be done in time for my current project, but at the moment the project is on hold until I can find a definitive answer to the issue. Thanks!
  3. Osian Evans 2015-03-09

    Could someone give some indication of what the process / timescale for this issue will be? Thanks!
  4. Michael Gangolf 2015-06-18

    Is it possible to get the preview image width/height? If you read this page: http://androblip.huiges.nl/2010/07/25/camera-preview-size-picture-size-and-scaling/ _"It seems that on the G1 the standard previewsize you get is 320 x 480, while the picture size is something like 1536 x 2048. A quick thinker sees that the preview is 2:3, while the picture is ofcourse 3:4"_ old phone but with my moto g2 I still have a difference between the size of the preview image and the actual photo. And when you have a overlay image and want to adjust the image its difficult when the image size differs.
  5. Michael Gangolf 2015-07-02

    I can't compile the whole sdk but something like this:
       static public KrollDict getPreviewSize(){
       		KrollDict dict = new KrollDict();
       
       		if (optimalPreviewSize!==null){
       			dict.put("width",optimalPreviewSize.width);
       			dict.put("height",optimalPreviewSize.height);
       		} else {
       			dict.put("width",0);
       			dict.put("height",0);
       		}
       		return dict;
       }
       
    in https://github.com/appcelerator/titanium_mobile/blob/17dc8754653daaff170ea0c18f74218168a5633e/android/modules/media/src/java/ti/modules/titanium/media/TiCameraActivity.java should probably work
  6. Radamantis Torres-Lechuga 2015-07-06

    [~oshevans] we can not replicate this issue, can you please send us more information in order to help us to reproduce the issue? Thanks
  7. Michael Gangolf 2015-07-06

    I can create a video and attach it later. E.g. Nexus 4 and Moto G2 produce different result
  8. Michael Gangolf 2015-07-06

    Attached the screen recordings. Make sure to watch them with Quicktime! VLC wasn't showing all frames! Moto G2: with overlay has a bigger image once the image was taken. Without the overlay the image size is the same as the preview size Nexus 4: with and without overlay the images look the same after taking the photo (although the preview image looks a bit stretched when you turn the camera (will upload a video of that in the evening)
  9. Michael Gangolf 2015-09-09

    any update here, do you need more information? Would like to see the preview-size added to the camera module
  10. Michael Gangolf 2015-09-17

  11. Shak Hossain 2015-09-29

    Marking this resolved. Will request to process the pull request.
  12. Srikanth Sombhatla 2015-10-02

    [~michael] Does previewRect property should be applied on the final preview image ?
  13. Michael Gangolf 2015-10-02

    @ssombhatla you mean inside the pull request? I've added it so it can be used like the croppedrect. When you just look at the preview (live camera) it looks fine but once the image is taken it will use a different image size (device depending) and I you are using overlays or need to positioning the camera image it will be different. E.g. I present an overlay with a box the user has to be inside. When taking the image the result will be different and you can't adjust the overlay because you don't know what the preview size was. With this pull request you should be able to adjust the overlay (according to: http://androblip.huiges.nl/2010/07/25/camera-preview-size-picture-size-and-scaling/)
  14. Srikanth Sombhatla 2015-10-07

    [~michael] Looks like this is an undocumented issue in Android Camera API and happens on specific devices. The anomaly in preview and final picture is because of horizontal field of view being greater in the final picture which is a result of preview and final picture having different aspect ratio. This results in extending both horizontal sides which are not visible in preview. Hence applying a cropped rect from (0,0) will not show the correct image as expected.

JSON Source