【问题标题】:Swift: Why CGImageCreateWithImageInRect() creates a rectangle 1 more pix larger?Swift:为什么 CGImageCreateWithImageInRect() 会创建一个大 1 个像素的矩形?
【发布时间】:2016-03-18 04:06:54
【问题描述】:

当我使用 CGImageCreateWithImageInRect() 创建一个 CGImage 时,它​​会创建一个比我传入的矩形高 1 px 和宽 1 px 的矩形。为什么会这样?

let rect: CGRect = CGRectMake(CGFloat(124.583333333333), CGFloat(156.416666666667), CGFloat(180.0), CGFloat(180.0))
let imgRef: CGImageRef = CGImageCreateWithImageInRect(img.CGImage, rect)!
print(rect.size)     // 180,180
print(CGImageGetWith(imgRef), CGImageGetHeight(imgRef))  // 181, 181

【问题讨论】:

    标签: swift swift2 cgrectmake


    【解决方案1】:

    您的CGRect 具有非整数来源。 CGImageCreateWithImageInRect 将使用 CGRect 重叠的任何像素(包括部分像素)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-19
      相关资源
      最近更新 更多