UIImage *image=[UIImageimageWithData:datasscale:0.8];
方法一:scrollView
#import "ViewController.h"
@interface ViewController ()<UIScrollViewDelegate>
@property (weak,nonatomic)IBOutletUIScrollView *scrollView;
@property (weak,nonatomic)IBOutletUIImageView *imageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
/**
scrollView中的内容滚动就必须要设置:滚动范围
contentSize : 子控件的大小,限定滚动的范围
contentSize 在设置的时候,一定要比scrollView的size要大
如果size中的宽度设为 0 ,就表示在横向中不能滚动
*/
_scrollView.contentSize =self.imageView.frame.size;
/**
minimumZoomScale; --> 最小的缩小倍数
maximumZoomScale; --> 最大的放大倍数
*/
_scrollView.minimumZoomScale =0.3;
_scrollView.maximumZoomScale =5;
// 设置控制器成为scrollView的代理
_scrollView.delegate =self;
[self.scrollViewsetZoomScale:1animated:YES];//设置缩放的倍数,如果缩放的倍数越大,scrollview滚动的范围也会变大,图片会变的模糊
// [self.scrollView zoomToRect:CGRectMake(0, 0, 300, 300) animated:YES];
}
// 返回的view将被拉伸(缩放)
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return_imageView;
}
// 只要图片在放大/缩小的过程中都会一直调用
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
NSLog(@"scrollViewDidZoom");
}
// 开始缩放的时候调用
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view {
NSLog(@"scrollViewWillBeginZooming");
}
// 结束的时候调用
// withView: 进行缩放的view
// atScale: 缩放的倍数
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale {
NSLog(@"scrollViewDidEndZooming--%f",scale);
}
================
方法二:quarter2D绘图
- (void)drawRect:(CGRect)rect {
//绘制图片
//1.加载图片
UIImage * image = [UIImageimageNamed:@"me"];
//2.绘制图片
[image drawAtPoint:CGPointMake(0,0)];//从指定点绘制,如果图片小区绘图区域,则会拉伸
// [image drawAsPatternInRect:rect];//以平铺的方式绘制
// [image drawInRect:rect];//以拉伸的方式绘制
}
UIImage *image=[UIImageimageNamed:@"tq"];
UIImageView *imageV=[[UIImageViewalloc]initWithImage:image];
// imageV.frame=self.view.frame;
imageV.frame=CGRectMake(0,0,200,300);
[self.viewaddSubview:imageV];
方法四:设置layer的transform属性来缩放
UIImage *image=[UIImageimageNamed:@"tq"];
UIImageView *imageV=[[UIImageViewalloc]initWithImage:image];
// imageV.frame=self.view.frame;
imageV.frame=CGRectMake(0,0,200,300);
[self.viewaddSubview:imageV];
//方法一: self.redLayer.transform = CATransform3DScale(self.redLayer.transform, 1, 1, 0.5);
// 方法二: self.redLayer.transform = CATransform3DMakeScale(0.5, 0.5, 1);
//KVC
// 方法三: NSValue * value = [NSValue valueWithCATransform3D:CATransform3DScale(self.redLayer.transform, 0.5, 0.5, 1)];
[self.redLayer setValue:value forKeyPath:@"transform"];
//方法四:用KVC的方式设置transform属性来缩放()
[imageV.layer setValue:@(2) forKeyPath:@"transform.scale.x"];//x轴方向放大两倍
[imageV.layer setValue:@(2) forKeyPath:@"transform.scale.y"];//y轴方向放大两倍
UIImage *image=[UIImage imageNamed:@"tq"];
UIImageView *imageV=[[UIImageView alloc]initWithImage:image];
// imageV.frame=self.view.frame;
imageV.frame=CGRectMake(0, 0, 200, 300);
[self.view addSubview:imageV];
imageV.transform=CGAffineTransformMakeScale(3,3);//宽高都放大3倍,这个方法是view的transform属性的方法
方法五。自带内容的控件,如imageview,button,会设置contentviewmodel来适应自身的大小;
CGSize newSize=CGSizeMake(100, 100);
或者
UIGraphicsBeginImageContextWithOptions(image.size,NO,0.2);//参数:上下文区域大小,是否透明,缩放率---相当于失真度
[image drawInRect:CGRectMake(0,0,image.size.width,image.size.height)];
UIImage*
newImage = UIGraphicsGetImageFromCurrentImageContext();//从图形上下文获取新的图片
UIGraphicsEndImageContext();
UIImage *image = info[UIImagePickerControllerEditedImage];
NSData *imageData = UIImageJPEGRepresentation(image, 0.2);//对图像做了压缩,0.2是失真度
方法八:图片拉伸:http://blog.csdn.net/u011146511/article/details/51233055