美文网首页专注iOS开发的小渣渣
相册选择图片,图片4:3处理

相册选择图片,图片4:3处理

作者: 蜗蜗牛在奔跑 | 来源:发表于2017-04-17 13:21 被阅读24次

    - (UIImage *)handleImage:(UIImage *)originalImage

    {

    CGSize originalsize = [originalImage size];

    CGImageRef imageRef = nil;

    CGFloat tempWidth = originalsize.width*0.75;

    CGFloat imageW = originalsize.width;

    imageRef = CGImageCreateWithImageInRect([originalImage CGImage], CGRectMake(0, originalsize.height/2-tempWidth*0.5, imageW, tempWidth));//获取图片整体部分

    UIGraphicsBeginImageContext(CGSizeMake(imageW, tempWidth));//指定要绘画图片的大小

    CGContextRef con = UIGraphicsGetCurrentContext();

    CGContextTranslateCTM(con, 0.0, tempWidth);

    CGContextScaleCTM(con, 1.0, -1.0);

    CGContextDrawImage(con, CGRectMake(0, 0, imageW, tempWidth), imageRef);

    UIImage *standardImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    CGImageRelease(imageRef);

    return standardImage;

    }

    使用:

    UIImage *newImage =  [self handleImage:image];

    相关文章

      网友评论

        本文标题:相册选择图片,图片4:3处理

        本文链接:https://www.haomeiwen.com/subject/fldtzttx.html