当前位置:编程学习 > wap >>

iPhone开发之小技巧:图片缩放(4)

[plain] 
static UIImage *shrinkImage(UIImage *original,CGSize size) 

    CGFloat scale = [UIScreen mainScreen].scale; 
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
    CGContextRef context = CGBitmapContextCreate(NULL, size.width*scale, size.height*scale, 8, 0, colorSpace, kCGImageAlphaPremultipliedFirst); 
    CGContextDrawImage(context, CGRectMake(0, 0, size.width*scale, size.height*scale), original.CGImage); 
    CGImageRef shrunken = CGBitmapContextCreateImage(context); www.zzzyk.com
    UIImage *final = [UIImage imageWithCGImage:shrunken]; 
     
    CGContextRelease(context); 
    CGImageRelease(shrunken); 
     
    return  final; 

作者:js_dada
补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,