0

I have taken photos for iPhone 5 portrait and landscape mode. photos reduced size 320 * 242 both modes but portrait mode photos stretched and landscape working perfectly

image view content mode set aspectfill. instagram application take photos landscape and portrait mode.not stretched any photos that size maintain 320 * 427

my didfinishwithmedia info code below:

 else if ([mediaType isEqualToString:(__bridge NSString *)kUTTypeImage])
{
    _imgcount = 0;
[self dismissViewControllerAnimated:YES completion:^{
    UIImage *image = [info objectForKey: UIImagePickerControllerOriginalImage];
    CGFloat imgHeight = image.size.height;
    CGFloat imgWidth = image.size.width;
    CGFloat resizeWidth = 320;
    CGFloat resizeHeight = 240;
    if (imgWidth > imgHeight) {
        resizeHeight = imgHeight * 320/imgWidth;
    }
    else if (imgWidth < imgHeight || imgHeight == imgWidth){
        resizeWidth = imgWidth * 240/imgHeight;
    }
     UIImage *compressedImage = [self scaleImage:image toSize:CGSizeMake(resizeWidth, resizeHeight)];
    if (checkgallery) {
        _imgcount += 1;
        imgBannerimage.image = compressedImage;
    }
    else{
        strMediatype = [NSString stringWithFormat:@"image"];
        imgtblVideo.image =compressedImage;
    }
    [tblDealership reloadData]; // Update table UI
}];
 }




 -(UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)newSize
  {
//    UIGraphicsBeginImageContext(newSize);
 UIGraphicsBeginImageContextWithOptions(newSize,NO,0.0);
 [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
 UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();
  return newImage;
  }

suggest with your ideas..

rajesh57
  • 275
  • 1
  • 3
  • 14

0 Answers0