cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Richard Marshall (JIRA)" <>
Subject [jira] [Created] (CB-4027) Using targetWidth & targetHeight with camera.getPicture does not return scaled image on WP7 WP8 PhoneGap
Date Thu, 27 Jun 2013 11:58:20 GMT
Richard Marshall created CB-4027:

             Summary: Using targetWidth & targetHeight with camera.getPicture does not
return scaled image on WP7 WP8 PhoneGap
                 Key: CB-4027
             Project: Apache Cordova
          Issue Type: Bug
          Components: Plugin Camera, WP7, WP8
    Affects Versions: 2.8.0
            Reporter: Richard Marshall
            Assignee: Steve Gill

I have built an app that uses the camera.getPicture.

I am using targetWidth & targetHeight to shrink the image to a smaller size before saving
it to a server.
The PhoneGap functionality is supposed to scale the image so as not to lose the aspect ratio
of the original image.
As mentioned in

The functionality is working fine in iOS and Android, but in Windows Phone it turns it into
a square with the width and height as set by targetWidth & targetHeight.

This is the call;, app.onPhotoDataFail, { quality: 50, targetWidth:400,
targetHeight:400, allowEdit: false, destinationType: app.destinationType.DATA_URL });

Looking at the PhoneGap 2.8 code in Plugins/Camera.cs

        private string GetImageContent(Stream stream)
            int streamLength = (int)stream.Length;
            byte[] fileData = new byte[streamLength + 1];
            stream.Read(fileData, 0, streamLength);

            //use photo's actual width & height if user doesn't provide width & height
            if (cameraOptions.TargetWidth < 0 && cameraOptions.TargetHeight <
                return Convert.ToBase64String(fileData);
                // resize photo
                byte[] resizedFile = ResizePhoto(stream, fileData);
                return Convert.ToBase64String(resizedFile);

        private byte[] ResizePhoto(Stream stream, byte[] fileData)
            int streamLength = (int)stream.Length;
            int intResult = 0;

            byte[] resizedFile;

            stream.Read(fileData, 0, streamLength);

            BitmapImage objBitmap = new BitmapImage();
            MemoryStream objBitmapStream = new MemoryStream(fileData);
            MemoryStream objBitmapStreamResized = new MemoryStream();
            WriteableBitmap objWB;
            objWB = new WriteableBitmap(objBitmap);

            // resize the photo with user defined TargetWidth & TargetHeight
            Extensions.SaveJpeg(objWB, objBitmapStreamResized, cameraOptions.TargetWidth,
cameraOptions.TargetHeight, 0, cameraOptions.Quality);

            //Convert the resized stream to a byte array.
            streamLength = (int)objBitmapStreamResized.Length;
            resizedFile = new Byte[streamLength]; //-1
            objBitmapStreamResized.Position = 0;
            //for some reason we have to set Position to zero, but we don't have to earlier
when we get the bytes from the chosen photo...
            intResult = objBitmapStreamResized.Read(resizedFile, 0, streamLength);

            return resizedFile;

You can see the if code that calls to resize the image.

When you look at the definition for Extensions.SaveJpeg

public static void LoadJpeg(this WriteableBitmap bitmap, Stream sourceStream);
        // Summary:
        //     Encodes a WriteableBitmap object into a JPEG stream, with parameters for
        //     setting the target width and height of the JPEG file.
        // Parameters:
        //   bitmap:
        //     The WriteableBitmap object.
        //   targetStream:
        //     The image data stream.
        //   targetWidth:
        //     The target width of the file.
        //   targetHeight:
        //     The target height of the file.
        //   orientation:
        //     This parameter is not currently used by this method. Use a value of 0 as
        //     a placeholder.
        //   quality:
        //     This parameter represents the quality of the JPEG photo with a range between
        //     0 and 100, with 100 being the best photo quality. We recommend that you do
        //     not fall lower than a value of 70. because JPEG picture quality diminishes
        //     significantly below that level.
        public static void SaveJpeg(this WriteableBitmap bitmap, Stream targetStream, int
targetWidth, int targetHeight, int orientation, int quality);

You can not see any reference to the fact that the aspect ratio will be kept anywhere in the
So it looks as if the aspect ratio is not honoured in the Windows Phone implementation of
the functionality.

Can we please have this fixed?

I originally posted here:!topic/phonegap/XNOhAqQDn4U


This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message