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

    一.步骤: 1.创建新的分区,并修改分区类型为8e 2.创建物理卷PV 3.将新建的PV添加到要扩展的VG中 4.用命令lvextend或lvresize来将新加入的PE添加到要扩展的LV中 5.用命 ...

  2. Eclipse下绿色安装插件Aptana、Swing

    本文主要针对Ecplise下绿色安装插件,写本篇博客也是因为笔者在Ecplise下安装Aptana时不断安装出现错误,所以写下自己安装成功以及之前出错的原因,也搜集了许多资料在此一并总结一下吧! Ec ...

  3. Java数据输入

    以下是数据输入实例: //以下是数据输入实例 import java.util.Scanner;//导入java.util.Scanner,Scanner首字母大写 public class Test ...

  4. iOS中UISearchBar(搜索框)使用总结

    http://my.oschina.net/u/2340880/blog/509756

  5. NSString字符串类型-学习总结

    1.字符串的创建 (1)创建常量字符串 NSString *str = @"This is a String"; //str是变量名 (2)创建空的字符串,给字符串赋值 NSStr ...

  6. Python代码一定要对齐

    不然会出现错误: IndentationError: unindent does not match any outer indentation level PS:新的Python语法,是不支持的代码 ...

  7. CDialog类中OnCancel()、OnInitDialog()作用

    1.void CCOMDDlg::OnCancel() { // TODO: Add extra cleanup here CDialog::OnCancel();} 如果把CDialog::OnCa ...

  8. 滚动到指定元素的id处+当元素出现在浏览器显示区域就会自动加载

    //滚动到指定元素的id处 如:$("#Exam82") function Jump() { var scroll_offset = $("#Exam82"). ...

  9. Erlang中的图形化检测工具(4)

    这儿例举出若干个用于检视运行时系统的图形化工具,这些工具可以很好地帮助我们增进对系统的理解.借助这些工具,我们可以很好地以图形化方式观察进程.应用和监督层级. (1) Appmon.Appmon 是用 ...

  10. Java中的日期处理类

    在Java中可以使用Date类和Calendar类来处理日期 但是Date类很多方法都过时了,推荐使用Canlendar类来处理日期,并对日期的格式化做了介绍.下面的部分将会逐一介绍 Date类 Ja ...