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 ...
随机推荐
- edittext实现粘贴表情
package com.sixin.view; import com.sixin.utile.FaceDataUtil; import android.annotation.SuppressLint; ...
- 使用Gradle构建Android应用内测版本
在开发应用的过程中,有时候需要比较当前线上版本和正在开发中的版本差异,目前的做法只能是在两个不同的设备上面安装线上版本和开发中的版本,因为当前版本在调试过程中会覆盖旧版本.本文通过使用gradle来构 ...
- MS-SQL数据库备份方法
一.手动备份 打开企业管理器 --> 右键点击需要备份的数据库 --> 所有任务 --> 备份数据库 或者: 查询分析器: use master backup database 数 ...
- VS2010 ReportViewer导出文件下载保存不能识别文件类型
今天测试项目时,突然发现导出报表下载保存的保存,不能识别文件的类型,文件名称为:.xls[3] 检查代码发现在指定报表路径时多了一个方法: ReportViewer1.LocalReport.Load ...
- C#中弹出新窗口
1.在主窗体程序中定义对应别的窗体的对象 Form_a_class form1 = Form_a_class test_delegate(); 2.调用显示 form1.ShowDialog();
- CDialog类中OnCancel()、OnInitDialog()作用
1.void CCOMDDlg::OnCancel() { // TODO: Add extra cleanup here CDialog::OnCancel();} 如果把CDialog::OnCa ...
- CSS的一些思考(一)
迈入前端行业已经8个多月了,从之前懵懵懂懂到现在的能根据设计图迅速成型页面,自我感觉良好.最近看到张大牛的一篇博客<说说CSS学习中的瓶颈>,突然意识到,自己不就处在快速学习和成长后的一个 ...
- MySQL 设置远程访问
MySQL远程访问,也就是通过ip访问MySQL服务,MySQL对于安全的要求是非常严格的,需要授权. 1.本地访问 GRANT ALL PRIVILEGES ON *.* TO admin@loca ...
- Linux - How To Set Up an NFS Mount on CentOS 6
About NFS (Network File System) Mounts NFS mounts work to share a directory between several servers. ...
- 5W1H分析法
"5W1H分析法"也叫"六何分析法",它是一种分析方法也可以说是一种创造技法.是对选定的项目.工序和操作,都要从原因(Why).对象(What).地点(Wher ...