腾讯视频 Objective C的图形类使用 连接:http://dwz.cn/zH6nM iphone
一.UIImage类是用来处理图像,好比在窗口上显示图像,从一个文件上读取图像等等。spa
1.UIImage提供了一下不一样的方法来读取图片,从而建立图像对象;orm
//从应用程序上读取图像,参数为文件名(文件已经拷贝在应用中)视频
+【UIImage imageNamed:(NSString *) name】对象
//从文件系统上读取图像,参数为完整文件名(包括路径信息)图片
- [UIImage initWithContentsOfFile:(NSString *)path]ip
- [UIImage initWithData:(NSData *)data]//从内存中读取图像数据内存
除了读取图像外,UIImage还能够生成一个bitmap图像。好比,用户在某一个应用程序的窗口上画了一个图,而后 应用程序能够将该图保存成一个bitmap图像。开发
-(UIImage *)saveToImage:(CGSize)size{get
UIImage *result=nil;
UIGraphicsBeginImageContext(size);
//调用画图的代码
result=UIGraphicsGetImageFromCurrentContext();//捕捉所化的图
UIGraphicsEndImageContext();
return result;
}
另外,你能够使用以下方法将图像转换成PNG和JPEG
NSData *UIImagePNGRepresentation(UIImage *image);
NSData *UIImageJPGRepresentation(UIImage *image);
UIImages也提供了drawRect方法,因此,开发人员能够调用下述方法画图:
-【UIImage drawAtPoint:(CGPoint)point】
-【UIImage drawAtPoint:(CGPoint)point】
-【UIImage drawAsPatternInRect :(CGRect)rect】
二.图像的滚动.放大和缩小
在建立视图时,你能够在界面建立器上设置UIScrollView的大小。
CGRect fram =CGRectMake(0,0,200,200);
scrollView =[[UIScrollView alloc] initWithFrame:frame];
首先建立图像视图,而后添加该图像视图到滚动视图下。最后设置滚动视图的大小为图像视图的大小:
frame=CGRectMake(0,0,500,500);
myImageView=【【UIImageView alloc】initWithFrame:frame】
【scrollView addSubview:myImageView];
scollView.contetSize=CGSizeMake(500,500);
在iphone中是经过UIScrollViewDelegate来完成。
初了滚动,UIScrollView也支持放大和缩小,好比:
scrollView.maximumZoomScale=2.0;
scrollView.minimumZoomScale=scrollView.size.width/myImage.size.width;