Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-2737

WP8: Camera.getPicture(); aspect ratio resize patch

    XMLWordPrintableJSON

    Details

      Description

      Hey there, noticed windows8 phone proj. was missing aspect ratio resize so added it in (Essentially copied iOS code)

      Camera.cs
              private struct ResizeDimension
              {
                  public int width;
                  public int height;
      
              }
      
              private ResizeDimension ResizeAspectRatio(int oWidth, int oHeight, int tWidth, int tHeight)
              {
      
                  ResizeDimension tgt;
      
      
                  float widthFactor = (float)tWidth / (float)oWidth;
                  float heightFactor = (float)tHeight / (float)oHeight;
                  float scaleFactor;
      
                  if (widthFactor > heightFactor)
                      scaleFactor = heightFactor;
                  else
                      scaleFactor = widthFactor;
      
                  tgt.width = (int)Math.Min((float)oWidth * scaleFactor, tWidth);
                  tgt.height= (int)Math.Min((float)oHeight * scaleFactor, tHeight);
      
      
                  return tgt;
              }
      

      and works via

      ResizeDimension rd = ResizeAspectRatio(image.PixelWidth, image.PixelHeight, cameraOptions.TargetWidth, cameraOptions.TargetHeight);

      image.SaveJpeg(stream, rd.width, rd.height, 0, cameraOptions.Quality);

      Cheers,
      Dim

        Attachments

          Activity

            People

            • Assignee:
              purplecabbage Jesse MacFadyen
              Reporter:
              dimitri.adamou Dimitri Adamou
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: