25

hi I want to send an image to a web service. But I want to resize user selected any image into 75 x 75 and send it to web service. How can I resize this image into 75 x 75

Thanks

iDia
  • 1,397
  • 8
  • 25
  • 44
  • http://stackoverflow.com/questions/10491080/uiimage-resizing-not-working-properly/10491692#10491692 check this awesome Answer by Rob – pmk Jun 10 '13 at 07:26

3 Answers3

41

Try to implement the code below. It may be helpful for you:

    CGRect rect = CGRectMake(0,0,75,75);
    UIGraphicsBeginImageContext( rect.size );
    [yourCurrentOriginalImage drawInRect:rect];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
Bill
  • 44,502
  • 24
  • 122
  • 213
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
33

Use this method to resize your image:

+(UIImage *)imageResize :(UIImage*)img andResizeTo:(CGSize)newSize
{
    CGFloat scale = [[UIScreen mainScreen]scale];
    /*You can remove the below comment if you dont want to scale the image in retina   device .Dont forget to comment UIGraphicsBeginImageContextWithOptions*/
    //UIGraphicsBeginImageContext(newSize);
    UIGraphicsBeginImageContextWithOptions(newSize, NO, scale);
    [img drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}
manujmv
  • 6,450
  • 1
  • 22
  • 35
7

try this code:

- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize
{
    UIGraphicsBeginImageContext(newSize);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();
    return newImage;
}
kirti Chavda
  • 3,029
  • 2
  • 17
  • 29