UIImageView UIImage
来源:互联网 发布:故事版软件 编辑:程序博客网 时间:2024/05/02 09:48
------------------------------------------------------------------------------------UIImage------------------------------------------------------------------------------------------
1: 将 UIImage 指定的像素以复制的方式进行拉伸.(IOS 4X 时代)
UIImage *img=[UIImage imageNamed:@"QQ20120614-2.png"];img=[img stretchableImageWithLeftCapWidth:10 topCapHeight:2];
注: 例如设定为 LeftCapWidth(左边宽度) 为 10. 那么IOS 会自动复制 位于 11 X轴 的 图像来填充图片的宽度不足的部分.
原图:
拉伸后:
2:将 UIImage 指定的像素以复制的方式进行拉伸.(IOS 5X 时代)
UIEdgeInsets edgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);img= [img resizableImageWithCapInsets:edgeInsets];
原理和4X时代的稍有不同, 这次可以借定4周的区域, 最终以中间区域来自动填充所需要阔达的区域.
注:复制的区域是图片的全比例去复制的,图片的像素大小是多少,就以多少来复制,不会默认按比例压缩.(特别注意)
那么复制的区域,如果有高清图片,会自动使用高清图片.@2x
3:如果要将 UIImage 保存的本地硬盘里 需转换为NSData
(PNG格式)
NSData *imageData = UIImagePNGRepresentation(image);
(JPG格式)(会自动填补透明区域为白色,需要要缓存圆角图的童鞋要注意了)
data = UIImageJPEGRepresentation(image, (CGFloat)1.0);
4:将 UIImage 压缩 减少NSData 的实际大小.
+(UIImage *)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize{ // Create a graphics image context UIGraphicsBeginImageContext(newSize); // Tell the old image to draw in this new context, with the desired // new size [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; // Get the new image from the context UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); // End the context UIGraphicsEndImageContext(); // Return the new image. return newImage;}
------------------------------------------------------------------------------------UIImageView------------------------------------------------------------------------------------------
1:关于UIImageView 实现圆角图片的方式
两种方式:
1:直接设置 CALayer 的 圆角 和 裁剪 函数,但是用多了会影响拖动动画的流畅性
[self.image1.layer setCornerRadius:15];[self.image1.layer setMasksToBounds:YES];
2:在不影响拖动动画的流畅性下,可将UIImage通过代码以重绘的方式裁剪掉成圆角 再赋值到 UIImageView里面.
参考链接:http://no001.blog.51cto.com/1142339/637732
------------------------------------------------------------------------------------UIImageView------------------------------------------------------------------------------------------
- UIImageView UIImage
- UIImage UIImageView
- UIImageView,UIImage,CGContextRef
- UIImageView和UIImage,CGContextRef
- UIImage,UIImageView,截取圆形
- UIImageView和UIImage
- UIImageView和UIImage
- IOS-UIImage和UIImageView区别
- IOS1.6-UIImageView 和 UIImage
- UIImage和UIImageView的区别
- uiimageview 读取uiimage的大小
- 拼接UIImage,一个UIImageView同时展示三张UIImage
- UIImageView和UIImage,CGContextRef 的一些知识点
- UIImageView和UIImage,CGContextRef 的一些知识点
- UIImageView和UIImage,CGContextRef 的一些知识点
- UIImage与UIImageView有神马关系?
- UIImage与UIImageView关系(=)
- UIImageView和UIImage,CGContextRef 的一些知识点
- 在list集合中对元素进行分组
- Android SmsManager 发送超长短信 接收不完整
- Aviary发布iOS和Android App 成功从Android插件转型独立应用
- 0 - 构造和运行模块
- MO/MT介绍
- UIImageView UIImage
- 运行时异常和受检查异常
- 工厂方法模式(Factory Method Pattern)
- Asterisk VS FreeSwitch
- 观察者模式(Observer Pattern)
- HTML5标签
- Linux添加/删除用户和用户组 基本概念
- 黑马程序员___交通灯学习心得
- 判断两个集合中是否存在相同的数据并去重