1.等比率縮放
- (UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize{
UIGraphicsBeginImageContext(CGSizeMake(image.size.width * scaleSize, image.size.height * scaleSize);
[image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height * scaleSize)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
2.自定長(zhǎng)寬
- (UIImage *)reSizeImage:(UIImage *)image toSize:(CGSize)reSize{
UIGraphicsBeginImageContext(CGSizeMake(reSize.width, reSize.height));
[image drawInRect:CGRectMake(0, 0, reSize.width, reSize.height)];
UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return reSizeImage;
}
3.處理某個(gè)特定View
只要是繼承UIView的object 都可以處理
必須先import QuzrtzCore.framework
-(UIImage*)captureView:(UIView *)theView{
CGRect rect = theView.frame;
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[theView.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
4.儲(chǔ)存圖片
儲(chǔ)存圖片這里分成儲(chǔ)存到app的文件里和儲(chǔ)存到手機(jī)的圖片庫(kù)里
- 儲(chǔ)存到app的文件里
NSString *path = [[NSHomeDirectory()stringByAppendingPathComponent:@"Documents"]stringByAppendingPathComponent:@"image.png"];
[UIImagePNGRepresentation(image) writeToFile:pathatomically:YES];
把要處理的圖片, 以image.png名稱存到app home下的Documents目錄里
2)儲(chǔ)存到手機(jī)的圖片庫(kù)里(必須在真機(jī)使用桃焕,模擬器無(wú)法使用)
CGImageRef screen = UIGetScreenImage();
UIImage* image = [UIImage imageWithCGImage:screen];
CGImageRelease(screen);
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
UIGetScreenImage(); // 原來(lái)是private(私有)api, 用來(lái)截取整個(gè)畫面,不過(guò)SDK 4.0后apple就開放了
轉(zhuǎn)載:http://blog.csdn.net/xuhuan_wh/article/details/6434055
SDWebImage:異步緩存加載網(wǎng)絡(luò)圖片 http://hao.jobbole.com/sdwebimage-ios/?utm_source=hao.jobbole.com&utm_medium=relatedResources