mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2025-03-17 06:21:03 +08:00
Merge branch 'CB-6612' of https://github.com/MSOpenTech/cordova-plugin-camera
This commit is contained in:
commit
10e5455356
@ -343,18 +343,8 @@ 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)
|
imageContent = ResizePhoto(stream);
|
||||||
{
|
|
||||||
int streamLength = (int)stream.Length;
|
|
||||||
imageContent = new byte[streamLength + 1];
|
|
||||||
stream.Read(imageContent, 0, streamLength);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// resize photo
|
|
||||||
imageContent = ResizePhoto(stream);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -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;
|
||||||
|
|
||||||
//Keep proportionally
|
// Calculate resultant image size
|
||||||
double ratio = Math.Min((double)cameraOptions.TargetWidth / objWB.PixelWidth, (double)cameraOptions.TargetHeight / objWB.PixelHeight);
|
int width, height;
|
||||||
int width = Convert.ToInt32(ratio * objWB.PixelWidth);
|
if (cameraOptions.TargetWidth >= 0 && cameraOptions.TargetHeight >= 0)
|
||||||
int height = Convert.ToInt32(ratio * objWB.PixelHeight);
|
{
|
||||||
|
// Keep proportionally
|
||||||
|
double ratio = Math.Min(
|
||||||
|
(double)cameraOptions.TargetWidth / objWB.PixelWidth,
|
||||||
|
(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())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user