- (UIImage *) thumbnailImageForImage:(UIImage *) image {
    CGSize origImageSize = image.size;
    
    CGRect newRect = CGRectMake(0, 0, 65, 65);
    
    //确定缩放倍数
    float ratio = MAX(newRect.size.width / origImageSize.width, newRect.size.height/origImageSize.height);
    
    //创建位图上下文
    UIGraphicsBeginImageContext(newRect.size);
    //确定绘图区域
    CGRect projectRect;
    projectRect.size.width = ratio * origImageSize.width;
    projectRect.size.height = ratio * origImageSize.height;
    projectRect.origin.x = (newRect.size.width - projectRect.size.width) * 0.5;
    projectRect.origin.y = (newRect.size.height - projectRect.size.height) * 0.5;
    
    //在矩形区域中绘图
    [image drawInRect:projectRect];
    
    //通过上下文得到UIImage对象
    UIImage * small = UIGraphicsGetImageFromCurrentImageContext();
    return small;
}

参考文档:《ios编程》(第二版)P.287(第16章 创建UITableViewCell子类)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-03-04
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
相关资源
相似解决方案