1

I am in trouble with my App and expecting your help. I want to upload photo with specific size**(1200*1800)** from library to server,and I need to get original image then compress it.

UIImage *image = [UIImage imageWithCGImage:[asset fullResolutionImage] scale:[asset scale] orientation:0];

Unfortunately my app will get crashed if the original image size is large than 20M. So is there any way to get the image with specific size from AssetsLibrary directly?

iPatel
  • 46,010
  • 16
  • 115
  • 137
Friday
  • 21
  • 4

1 Answers1

1

I just Put some Helpful code, i am not sure but might be helpful in your case:

For Get Crop Image:

UIImage *croppedImg = nil;
CGRect cropRect = CGRectMake(AS YOu Need);
croppedImg = [self croppIngimageByImageName:self.imageView.image toRect:cropRect];

Use following method that return UIImage (as You want size of image)

- (UIImage *)croppIngimageByImageName:(UIImage *)imageToCrop toRect:(CGRect)rect
    {
        //CGRect CropRect = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height+15);

        CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage], rect);
        UIImage *cropped = [UIImage imageWithCGImage:imageRef];
        CGImageRelease(imageRef);

        return cropped;
    }

Here you get Croped Image that return by above method;

OR RESIZING

And also Use following method for specific hight and width with image for Resizing UIImage:

+ (UIImage*)resizeImage:(UIImage*)image withWidth:(int)width withHeight:(int)height
{
    CGSize newSize = CGSizeMake(width, height);
    float widthRatio = newSize.width/image.size.width;
    float heightRatio = newSize.height/image.size.height;

    if(widthRatio > heightRatio)
    {
        newSize=CGSizeMake(image.size.width*heightRatio,image.size.height*heightRatio);
    }
    else
    {
        newSize=CGSizeMake(image.size.width*widthRatio,image.size.height*widthRatio);
    }


    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return newImage;
}

This method return NewImage, with specific size that you want.

iPatel
  • 46,010
  • 16
  • 115
  • 137
  • But how can I get original image(imageToCrop or image)? If it's size is too large, my app will receive low memory warning and get crashed when I get original image from AssetsLibrary. – Friday Jul 18 '13 at 08:50