/*
     设置圆角,通过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. BGP

    http://network.51cto.com/art/200912/172439.htm http://blog.sina.com.cn/s/blog_b457dde80101cyqr.html ...

  2. Linux的目录结构及其作用

    /bin bin是Binary的缩写.这个目录存放着最经常使用的命令. /boot这里存放的是启动Linux时使用的一些核心文件,包括一些连接文件以及镜像文件. /dev dev是Device(设备) ...

  3. C# 扩展方法克隆实体类

    using System; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using System.Ru ...

  4. hdu5347 MZL's chemistry(打表)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud MZL's chemistry Time Limit: 2000/1000 MS ...

  5. org.hibernate.service.jndi.JndiException: Error parsing JNDI name []

    我的hibernate.cfg.xml文件如下: <?xml version="1.0" encoding="UTF-8"?> <!DOCTY ...

  6. mysql查询unicode字符串

    mysql查询的时候会将\干掉,可以用mysql的like通配符来做like '%\u5f20\u4e09%'变成like '%_u5f20_u4e09%'

  7. Hql 子查询

    直接上代码: public virtual IList<VoucherLog> GetMaxResultVoucherLog() { string orgaizationCode = Ht ...

  8. mysql 套事物实例

    public static DataSet GetPPriceList(string aircompany, string departPort, string arrivePort, string ...

  9. php 和 apache的关系

    例如在客户端游览器输入他也回把这个地址传送到192.168.1.100里的apache里的,apache一看你传过来的是Php文件,如果在服务器没装php的情况下,他也会把这个文件打开,把里面的代码全 ...

  10. Core Data (一)备

    序 恩,用Core Data也有一段时间了.大大小小的坑也都坑过了.重来没有认真的记录一次.这次需要好好的理一理Core Data.就当一次绝好的机会记录下来.也为了自己加深认识. 为什么要用Core ...