UIImageView圆角,自适应图片宽高比例,图片拉伸,缩放比例和图片缩微图
/*
设置圆角,通过layer中的cornerRadius和masksToBounds即可。
自适应图片宽高比例。通过UIViewContentModeScaleAspectFit设置,注意这个UIImageView的frame就不是init中的数据了。
同样的UIImage图片放入不同frame中的UIImageView就可以实现比例缩放了。只是UIImageView的大小改变了,
*/
UIImage* image = [UIImage imageNamed:@"back2.jpg"];
UIImageView* imageView1 = [[[UIImageView alloc] initWithImage:image] autorelease];
imageView1.frame = CGRectMake(0, 0, 300, 200);
imageView1.center = CGPointMake(150, 200);
//设置圆角
imageView1.layer.cornerRadius = 8;
imageView1.layer.masksToBounds = YES;
//自适应图片宽高比例
imageView1.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:imageView1];
//拉伸图片
CGFloat capWidth = image.size.width / 2;
CGFloat capHeight = image.size.height / 2;
UIImage* stretchableImage = [image stretchableImageWithLeftCapWidth:capWidth topCapHeight:capHeight];
UIImageView* imageView3 = [[[UIImageView alloc] initWithImage:stretchableImage] autorelease];
imageView3.frame = CGRectMake(0, 0, 300, 200);
imageView3.center = CGPointMake(150, 200);
[self.view addSubview:imageView3];
//改变frame改变
UIImageView* imageView4 = [[[UIImageView alloc] initWithImage:image] autorelease];
imageView4.frame = CGRectMake(0, 0, 300/2, 200/2);
imageView4.center = CGPointMake(150, 200);
[self.view addSubview:imageView4];
- (UIImage *)generatePhotoThumbnail:(UIImage *)image {
// Create a thumbnail version of the image for the event object.
CGSize size = image.size;
CGSize croppedSize;
CGFloat ratioX = 75.0;
CGFloat ratioY = 60.0;
CGFloat offsetX = 0.0;
CGFloat offsetY = 0.0;
// check the size of the image, we want to make it
// a square with sides the size of the smallest dimension
if (size.width > size.height) {
offsetX = (size.height - size.width) /
2;
croppedSize = CGSizeMake(size.height, size.height);
} else {
offsetY = (size.width - size.height) /
2;
croppedSize = CGSizeMake(size.width, size.width);
}
// Crop the image before resize
CGRect clippedRect = CGRectMake(offsetX * -1, offsetY * -1, croppedSize.width, croppedSize.height);
CGImageRef imageRef =
CGImageCreateWithImageInRect([image CGImage], clippedRect);
// Done cropping
// Resize the image
CGRect rect = CGRectMake(0.0,
0.0, ratioX, ratioY); // 设置图片缩微图的区域((0,0),宽:75 高:60)
UIGraphicsBeginImageContext(rect.size);
[[UIImage imageWithCGImage:imageRef]
drawInRect:rect];
UIImage *thumbnail =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Done Resizing
return thumbnail;
}
UIImageView圆角,自适应图片宽高比例,图片拉伸,缩放比例和图片缩微图的更多相关文章
- css图片根据div宽高比例自适应
1.div布局 <div class="card-img-show"> <div class="upload-img-conss" > ...
- css+background实现 图片宽高自适应,拉伸裁剪不变形
图片宽高不固定 ,一样实现自适应,拉伸裁剪不变形,适应各大兼容性. 下面咱们在网上找两张宽高不一样的照片: No.1 ...
- 关于Google圆角高光高宽自适应按钮及其拓展
关于Google圆角高光高宽自适应按钮及其拓展————源自张鑫旭css讲解 这篇文章发布于 2009年10月24日,星期六,18:08,归类于 css相关. 阅读 48770 次, 今日 1 次 by ...
- 一行实现QQ群组头像,微信群组,圆角等效果. 并支持url直接加载图片
说点题外话. Coding中我们总是经历着这么几个过程. 学会使用: 不管是API也好, 开源库也好. 总是在最开始的学会去用. 了解实现原理: 可能会因为一些不兼容, 代码的异常状态的处理不够完美等 ...
- css3圆形头像(当图片宽高不相等时)
1.图片宽高相等,width:300px: height:300px; 把他变成宽高100px的圆形头像 img{width:100px; height:100px; border-radius:50 ...
- 加载的过程中图片变形了? --教你自定义自动适配图片宽高比的RatioLayout
很多同行在开发中可能会遇到这样的问题,就是在加载图片的时候会出现图片变形的问题.其实这很可能就是你的图片宽高比和图片所在容器的宽高比不匹配造成的.比如说图片的宽为200,高为100.宽高比就是2,那么 ...
- JS实现图片宽高的等比缩放
关于图片宽高的等比缩放,其实需求就是让图片自适应父容器的宽高,并且是等比缩放图片,使图片不变形. 例如,需要实现如下的效果: 要实现上面的效果,需要知道图片的宽高,父容器的宽高,然后计算缩放后的宽高. ...
- ios UIWebView加载HTMLStr图文,关于图片宽高设置,webView内容实际高度的踩坑问题
一.关于UIWebView 与 WKWebView 选取问题 从发布时间看: 2008年7月11日,在新一代iPhone3G正式发售当天,iPhone OS 2.0(iOS 2.0)推出,这时候就有U ...
- php 图片上传的公共方法(按图片宽高缩放或原图)
写的用于图片上传的公共方法类调用方法: $upload_name='pic';$type = 'logo_val';$file_name = 'logo_' . $user_id .create_st ...
随机推荐
- [CSAPP笔记][第十章 系统级I/O]
第十章 系统级I/O 输入/输出(I/O) : 是指主存和外部设备(如磁盘,终端,网络)之间拷贝数据过程. 高级别I/O函数 scanf和printf <<和>> 使用系统级I ...
- openssl 非对称加密算法DSA命令详解
1.DSA算法概述 DSA算法是美国的国家标准数字签名算法,它只能用户数字签名,而不能用户数据加密和密钥交换. DSA与RSA的生成方式不同,RSA是使用openssl提供的指令一次性的生成密钥(包括 ...
- CentOS CVS安装使用
CentOS CVS安装使用 一.CVS简介 CVS(Concurrent Versions System)版本控制系统:是一种GNU软件包,CVS是一个C/S系统,主要用于在多人开发环境下的源码 ...
- Linux 下安装oracle数据库
原文出处 http://www.linuxidc.com/Linux/2015-02/113222.html 需要安装Oracle DataGuard,所以先要安装单台Oracle11g, ...
- kafka的一些常用命令
启动zookeeper bin/zookeeper-server-start.sh config/zookeeper.properties & 启动kafka bin/kafka-server ...
- C# Serializable学习
先上代码,感觉这个功能很给力啊. class Program { static void Main(string[] args) { //下面代码将对象Person进行序列化并存储到一个文件中 Per ...
- AngularJS的$http服务的应用
$http有很多参数和调用方法,本文只记录比较常用的应用及参数. $http 服务:只是简单封装了浏览器原生的XMLHttpRequest对象,接收一个参数,这个参数是一个对象,包含了用来生成HTTP ...
- seajs模块压缩问题
在优化整理项目代码时,想使用seajs来把代码模块化.看了下官方5分钟上手教程,觉得很不错,也没多想就一直开发下去了,也没出什么问题.等一同事说把代码打包个放到设备上去测试一下,发现怎么也跑不起来,郁 ...
- Unsupported major.minor version 52.0 处理方式
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/globalroam/openstac ...
- Form 表单常用正则验证 (收藏)
1.^\d+$ //匹配非负整数(正整数 + 0) 2.^[0-9]*[1-9][0-9]*$ //匹配正整数 3.^((-\d+)|(0+))$ //匹配非正整数(负整数 + 0) 4.^-[0-9 ...