如何将UIImage缩放到指定大小尺寸
问题:如何将UIImage缩放到指定大小尺寸?答案:[mw_shl_code=c,true]-(UIImage*)scaleToSize:(UIImage*)imgsiz...
问题:如何将UIImage缩放到指定大小尺寸?答案:[mw_shl_code=c,true]- (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{ // 创建一个bitmap的context // 并把它设置成为当前正在使用的context UIGraphicsBeginImageContext(size); // 绘制改变大小的图片 [img drawInRect:CGRectMake(0, 0, size.width, size.height)]; // 从当前context中创建一个改变大小后的图片 UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext(); // 使当前的context出堆栈 UIGraphicsEndImageContext(); // 返回新的改变大小后的图片 return scaledImage; }[/mw_shl_code]
展开
1个回答
展开全部
+ (CGSize)fitsize:(CGSize)thisSize{ if(thisSize.width == 0 && thisSize.height ==0) return CGSizeMake(0, 0); CGFloat wscale = thisSize.width/IMAGE_MAX_SIZE_WIDTH; CGFloat hscale = thisSize.height/IMAGE_MAX_SIZE_GEIGHT; CGFloat scale = (wscale>hscale)?wscale:hscale; CGSize newSize = CGSizeMake(thisSize.width/scale, thisSize.height/scale); return newSize;}//根据图片的大小等比例压缩返回图片+(UIImage *)fitSmallImage:(UIImage *)image{ if (nil == image) { return nil; } if (image.size.width<IMAGE_MAX_SIZE_WIDTH && image.size.height<IMAGE_MAX_SIZE_GEIGHT) { return image; } CGSize size = [DSMDataConvert fitsize:image.size]; UIGraphicsBeginImageContext(size); CGRect rect = CGRectMake(0, 0, size.width, size.height); [image drawInRect:rect]; UIImage *newing = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newing;} 查看原帖>>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询