2

Does any one how to reduce image size without changing the dimensions of that image programmaticallyin iphone?

Shakti
  • 1,889
  • 4
  • 18
  • 29

1 Answers1

0

// There is 3 way that were known to me.
// 1. Use just resize

    UIImageView *iView = ...;
    CGRect orgFrame = iView.frame;
    iView.contentMode = UIViewContentModeScaleAspectFit;
    iView.frame = CGRectMake(CGRectGetMinX(orgFrame), CGRectGetMinY(orgFrame),
                             CGRectGetWidth(orgFrame)*.5, CGRectGetHeight(orgFrame)*.5);

// 2. Use affineTransform for just display.
// It use 3x3 matrix for scaling.
// UIView has

@property(nonatomic) CGAffineTransform transform

// Usage:

    UIImageView *iView = ...;
    iView.transform = CGAffineTransform(.5f, .5f);
    // ==> will display 1/2 size view.

// 3. Use CALayer renderInContext: for get reduced Image

    UIImage *sourceImage = ...;
    CGSize *reducedSize = CGSizeMake(CGRectGetWidth(sourceImage.frame)*.5f, CGRectGetHeight(sourceImage.frame)*.5f);
    UIImage *reducedImage; {
        UIImageView *imageView = [UIImageView initWithImage:sourceImage];

        UIGraphicsBeginImageContext(reducedSize);
        imageView.transform = CGAffineTransform(.5f, .5f);
        [imageView renderInContext:UIGraphicsGetCurrentContext()];

        reduceImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    }
    ...
TopChul
  • 419
  • 2
  • 14
  • Thanks for your help. But I have an UIImage, which i am getting from the iPhone photo album and not the UIImageView. – Shakti Jun 02 '11 at 02:34