美文网首页iOS Developer
image改变size时不清晰的问题

image改变size时不清晰的问题

作者: 什么的黑夜 | 来源:发表于2016-11-16 10:56 被阅读61次

不清晰写法

- (UIImage *)reSizeImage:(UIImage *)image toSize:(CGSize)reSize

{

     UIGraphicsBeginImageContext(reSize);

     [image drawInRect:CGRectMake(0, 0, reSize.width, reSize.height)];

     UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();

     UIGraphicsEndImageContext();

     return reSizeImage;

}

修改过后

-(UIImage *)reSizeImage:(UIImage *)image toSize:(CGSize)reSize
{

    //instead of UIGraphicsBeginImageContext(reSize);

    UIGraphicsBeginImageContextWithOptions(reSize, YES, 0); 

    [image drawInRect:CGRectMake(0, 0, reSize.width, reSize.height)];

    UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return reSizeImage;

}

补充说明

void UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale);
size——同UIGraphicsBeginImageContext
opaque——透明开关,如果图形完全不用透明,设置为YES以优化位图的存储。
scale—–缩放因子:设为0后,系统就会自动设置正确的比例了

相关文章

网友评论

    本文标题:image改变size时不清晰的问题

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