zoukankan      html  css  js  c++  java
  • 获取图片的缩略图

    - (UIImage *) thumbnailImageForImage:(UIImage *) image {
        CGSize origImageSize = image.size;
        
        CGRect newRect = CGRectMake(0, 0, 65, 65);
        
        //确定缩放倍数
        float ratio = MAX(newRect.size.width / origImageSize.width, newRect.size.height/origImageSize.height);
        
        //创建位图上下文
        UIGraphicsBeginImageContext(newRect.size);
        //确定绘图区域
        CGRect projectRect;
        projectRect.size.width = ratio * origImageSize.width;
        projectRect.size.height = ratio * origImageSize.height;
        projectRect.origin.x = (newRect.size.width - projectRect.size.width) * 0.5;
        projectRect.origin.y = (newRect.size.height - projectRect.size.height) * 0.5;
        
        //在矩形区域中绘图
        [image drawInRect:projectRect];
        
        //通过上下文得到UIImage对象
        UIImage * small = UIGraphicsGetImageFromCurrentImageContext();
        return small;
    }

    参考文档:《ios编程》(第二版)P.287(第16章 创建UITableViewCell子类)

  • 相关阅读:
    map
    01背包和完全背包 POJ
    并查集 计算节点数量
    set
    map,vector,queue 图 综合运用
    并查集 hdu-1325 Is It A Tree?
    js中的ajax
    java算法
    MySql在Window上的安装
    微信开发账号要求
  • 原文地址:https://www.cnblogs.com/benbenzhu/p/3669222.html
Copyright © 2011-2022 走看看