This commit is contained in:
Jesse MacFadyen 2014-05-08 15:06:17 -07:00
commit 10e5455356

View File

@ -343,19 +343,9 @@ namespace WPCordovaClassLib.Cordova.Commands
try try
{ {
//use photo's actual width & height if user doesn't provide width & height // Resize photo and convert to JPEG
if (cameraOptions.TargetWidth < 0 && cameraOptions.TargetHeight < 0)
{
int streamLength = (int)stream.Length;
imageContent = new byte[streamLength + 1];
stream.Read(imageContent, 0, streamLength);
}
else
{
// resize photo
imageContent = ResizePhoto(stream); imageContent = ResizePhoto(stream);
} }
}
finally finally
{ {
stream.Dispose(); stream.Dispose();
@ -368,7 +358,6 @@ namespace WPCordovaClassLib.Cordova.Commands
/// Resize image /// Resize image
/// </summary> /// </summary>
/// <param name="stream">Image stream</param> /// <param name="stream">Image stream</param>
/// <param name="fileData">File data</param>
/// <returns>resized image</returns> /// <returns>resized image</returns>
private byte[] ResizePhoto(Stream stream) private byte[] ResizePhoto(Stream stream)
{ {
@ -382,10 +371,22 @@ namespace WPCordovaClassLib.Cordova.Commands
WriteableBitmap objWB = new WriteableBitmap(objBitmap); WriteableBitmap objWB = new WriteableBitmap(objBitmap);
objBitmap.UriSource = null; objBitmap.UriSource = null;
// Calculate resultant image size
int width, height;
if (cameraOptions.TargetWidth >= 0 && cameraOptions.TargetHeight >= 0)
{
// Keep proportionally // Keep proportionally
double ratio = Math.Min((double)cameraOptions.TargetWidth / objWB.PixelWidth, (double)cameraOptions.TargetHeight / objWB.PixelHeight); double ratio = Math.Min(
int width = Convert.ToInt32(ratio * objWB.PixelWidth); (double)cameraOptions.TargetWidth / objWB.PixelWidth,
int height = Convert.ToInt32(ratio * objWB.PixelHeight); (double)cameraOptions.TargetHeight / objWB.PixelHeight);
width = Convert.ToInt32(ratio * objWB.PixelWidth);
height = Convert.ToInt32(ratio * objWB.PixelHeight);
}
else
{
width = objWB.PixelWidth;
height = objWB.PixelHeight;
}
//Hold the result stream //Hold the result stream
using (MemoryStream objBitmapStreamResized = new MemoryStream()) using (MemoryStream objBitmapStreamResized = new MemoryStream())