生成缩略图

匿名 (未验证) 提交于 2019-12-03 00:22:01

废话不多说,直接上代码

/**

@param image 传入图片

@param asize 需求的大小

@return 缩略图

+(UIImage *)thumbnailWithImageWithoutScale:(UIImage *)image size:(CGSize)asize

{

UIImage *newimage;

if (nil == image) {

nil;

else{

CGSize oldsize = image.size;

CGRect rect;

if (asize.width/asize.height > oldsize.width/oldsize.height) {

size.width = asize.height*oldsize.width/oldsize.height;

size.height = asize.height;

origin.x = (asize.width - rect.size.width)/2;

origin.y = 0;

else{

size.width = asize.width;

size.height = asize.width*oldsize.height/oldsize.width;

origin.x = 0;

origin.y = (asize.height - rect.size.height)/2;

UIGraphicsBeginImageContext(asize);

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);

UIRectFill(CGRectMake(0, 0, asize.width, asize.height));//clear background

drawInRect:rect];

UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return newimage;

}

文章来源: 生成缩略图
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!