/*
     设置圆角,通过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圆角,自适应图片宽高比例,图片拉伸,缩放比例和图片缩微图的更多相关文章

  1. css图片根据div宽高比例自适应

    1.div布局 <div class="card-img-show"> <div class="upload-img-conss" > ...

  2. css+background实现 图片宽高自适应,拉伸裁剪不变形

    图片宽高不固定 ,一样实现自适应,拉伸裁剪不变形,适应各大兼容性.  下面咱们在网上找两张宽高不一样的照片:     No.1                                      ...

  3. 关于Google圆角高光高宽自适应按钮及其拓展

    关于Google圆角高光高宽自适应按钮及其拓展————源自张鑫旭css讲解 这篇文章发布于 2009年10月24日,星期六,18:08,归类于 css相关. 阅读 48770 次, 今日 1 次 by ...

  4. 一行实现QQ群组头像,微信群组,圆角等效果. 并支持url直接加载图片

    说点题外话. Coding中我们总是经历着这么几个过程. 学会使用: 不管是API也好, 开源库也好. 总是在最开始的学会去用. 了解实现原理: 可能会因为一些不兼容, 代码的异常状态的处理不够完美等 ...

  5. css3圆形头像(当图片宽高不相等时)

    1.图片宽高相等,width:300px: height:300px; 把他变成宽高100px的圆形头像 img{width:100px; height:100px; border-radius:50 ...

  6. 加载的过程中图片变形了? --教你自定义自动适配图片宽高比的RatioLayout

    很多同行在开发中可能会遇到这样的问题,就是在加载图片的时候会出现图片变形的问题.其实这很可能就是你的图片宽高比和图片所在容器的宽高比不匹配造成的.比如说图片的宽为200,高为100.宽高比就是2,那么 ...

  7. JS实现图片宽高的等比缩放

    关于图片宽高的等比缩放,其实需求就是让图片自适应父容器的宽高,并且是等比缩放图片,使图片不变形. 例如,需要实现如下的效果: 要实现上面的效果,需要知道图片的宽高,父容器的宽高,然后计算缩放后的宽高. ...

  8. ios UIWebView加载HTMLStr图文,关于图片宽高设置,webView内容实际高度的踩坑问题

    一.关于UIWebView 与 WKWebView 选取问题 从发布时间看: 2008年7月11日,在新一代iPhone3G正式发售当天,iPhone OS 2.0(iOS 2.0)推出,这时候就有U ...

  9. php 图片上传的公共方法(按图片宽高缩放或原图)

    写的用于图片上传的公共方法类调用方法: $upload_name='pic';$type = 'logo_val';$file_name = 'logo_' . $user_id .create_st ...

随机推荐

  1. .net中将DataTable导出到word、Excel、txt、htm的方法

    dt:DataTable strFile:fileName strExt:type private void GridExport(DataTable dt, string strFile, stri ...

  2. Windows命令行(DOS命令)教程–2 (转载) http://arch.pconline.com.cn//pcedu/rookie/basic/10111/15325_1.html

    二.符号约定 为了便于说明格式,这里我们使用了一些符号约定,它们是通用的: C: 盘符 Path 路径 Filename 文件名 .ext 扩展名 Filespec 文件标识符 [ ] 方括号中的项目 ...

  3. javascript 概述及基础知识点(变量,常量,运算符,数据类型)

    JavaScript概述 1.1 什么是JavaScript: javaScript(简称js),是一种基于对象和事件驱动并具有相对安全性的客户端脚本语言.同时也是一种广泛用于客户端Web开发的脚本语 ...

  4. 视差滚动(Parallax Scrolling)效果的原理与实现

    视差滚动(Parallax Scrolling)效果的原理与实现1.视差滚动效果的主要特点:    1)直观的设计,快速的响应速度,更合适运用于单页面    2)差异滚动 分层视差    页面上很多的 ...

  5. [转发]Gulp开发教程(翻译)

    Building With Gulp =================== 转载出处 原文地址 翻译出处 对网站资源进行优化,并使用不同浏览器测试并不是网站设计过程中最有意思的部分,但是这个过程中的 ...

  6. 一篇详细的 Mysql Explain 详解

    一.语法 explain < table_name > 例如: explain select * from t3 where id=3952602; 二.explain输出解释 +—-+— ...

  7. CSS定义网页滚动条

    (一)滚动条样式主要涉及到如下CSS属性: overflow属性: 检索或设置当对象的内容超过其指定高度及宽度时如何显示内容overflow: auto; 在需要时内容会自动添加滚动条overflow ...

  8. Song of Pi

    def main(): pi = ' # 预先给出需要比较的值 t = int(raw_input()) for _ in xrange(t): song = raw_input().strip(). ...

  9. Android-2

    传递简单数据 //发送方i.putExtra("data",t.getText().toString()); //接收方Intent i = getIntent();m = (Ed ...

  10. mysql 命令行 自动补全

    配置文件中 默认关闭自动补全: [mysql] #no-auto-rehash # faster start of mysql but no tab completition 改为: [mysql] ...