ref:http://stackoverflow.com/questions/15439564/simple-resizing-of-uiimage-in-xcode
UIImage 讀取方式有以下兩種
UIImage *img = [UIImage imageNamed:@"test.png"]; // caching
UIImage *img = [UIImage imageWithContentsOfFile:@"test.png"]; // no caching
如果還是一樣大,還是改變你的尺寸吧一m一+
UIImage 讀取方式有以下兩種
UIImage *img = [UIImage imageNamed:@"test.png"]; // caching
UIImage *img = [UIImage imageWithContentsOfFile:@"test.png"]; // no caching
如果還是一樣大,還是改變你的尺寸吧一m一+
- (UIImage*)resizeImage:(UIImage *)image
{
CGSize origImageSize = [image size];
CGRect newRect = self.view.frame; //新的frame,要改的size
float ratio = MAX(newRect.size.width / origImageSize.width,
newRect.size.height / origImageSize.height);
UIGraphicsBeginImageContextWithOptions(newRect.size, NO, 0.0);
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:newRect
cornerRadius:5.0];
[path addClip];
CGRect imageRect;
imageRect.size.width = ratio * origImageSize.width;
imageRect.size.height = ratio * origImageSize.height;
imageRect.origin.x = (newRect.size.width - imageRect.size.width) / 2.0;
imageRect.origin.y = (newRect.size.height - imageRect.size.height) / 2.0;
[image drawInRect:imageRect];
UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return smallImage;
}
沒有留言:
張貼留言