zoukankan      html  css  js  c++  java
  • <12>保持原来的长宽比,生成一个缩略图

    /*
     * 保持原来的长宽比,生成一个缩略图
     * &-image 待传入UIImage
     * &-size 待传入UIImage要改变图像的尺寸
     * 返回处理好的UIImage
     */
    + (UIImage *)thumbnailWithImageWithoutScale:(UIImage *)image size:(CGSize)siz/** * 保持原来的长宽比,生成一个缩略图 */
    + (UIImage *)thumbnailWithImageWithoutScale:(UIImage *)image size:(CGSize)size
    {
        UIImage *newimage;
        if (nil == image) {
            newimage = nil;
        }
    else{
            CGSize oldsize = image.size;
            CGRect rect;
            if (size.width/size.height > oldsize.width/oldsize.height) {
                rect.size.width = size.height*oldsize.width/oldsize.height;
                rect.size.height = size.height;
                rect.origin.x = (size.width - rect.size.width)/2;
                rect.origin.y = 0;
            }
            else{
                rect.size.width = size.width;
                rect.size.height = size.width*oldsize.height/oldsize.width;
                rect.origin.x = 0;
                rect.origin.y = (size.height - rect.size.height)/2;
            }
            UIGraphicsBeginImageContext(size);
            CGContextRef context = UIGraphicsGetCurrentContext();
            CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
            UIRectFill(CGRectMake(0, 0, size.width, size.height));//clear background
            [image drawInRect:rect];
            newimage = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();
        }
        return newimage;
    }
     
  • 相关阅读:
    SQl 语句(常见) 新建,删除,修改表结构
    3步把您的java程序转换为webservice
    JSP标签中不要省略引号
    图文并茂——使用xfire编写webservice,并通过C#调用
    Java取随机数
    JAVA获取文件本身所在的磁盘位置
    XFire 入门
    mysql复制表和表结构
    遍历HashMap及获取所有的Key值
    MyEclipse+struts+Hibernate配置开发
  • 原文地址:https://www.cnblogs.com/iQingYang/p/6687948.html
Copyright © 2011-2022 走看看