gpt4 book ai didi

ios - UIImage drawInRect 不按比例绘制

转载 作者:可可西里 更新时间:2023-11-01 01:44:21 27 4
gpt4 key购买 nike

我正在尝试缩小 2 倍图像,然后在矩形中绘制 UIImage,但不知何故这没有任何效果。即使 .scale 属性发生变化,图像看起来仍具有相同的比例。

这是我的drawRect()

的实现
   override func drawRect(rect: CGRect) {
// Load the artwork
let areaRect = CGRect(x: 0, y: 0, width: rect.width, height: rect.height)
var art = UIImage(named: "art-1-square-640")
// Make the circular mask
let maskRef = UIImage(named: "art-circular-mask").CGImage
let maskCircle = CGImageMaskCreate(
UInt(rect.width),
UInt(rect.height),
CGImageGetBitsPerComponent(maskRef),
CGImageGetBitsPerPixel(maskRef),
CGImageGetBytesPerRow(maskRef),
CGImageGetDataProvider(maskRef),
nil,
false)
let artMaskedRef = CGImageCreateWithMask(art.CGImage, maskCircle)
var artMasked = UIImage(CGImage: artMaskedRef, scale: 0.5, orientation: UIImageOrientation.Up);
artMasked.drawInRect(areaRect)
}

最佳答案

scale:0.5 表示图像中每个像素有两个点,而不是正常情况下(对于 @2x 图像)每个点有两个像素。这将使图像大 4 倍。然而,drawInRect 并不关心,它只是将图像缩小以适合矩形。

关于ios - UIImage drawInRect 不按比例绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24471596/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com