gpt4 book ai didi

iphone - 绘制矩形 :boxRect vs CGContextDrawImage

转载 作者:行者123 更新时间:2023-12-01 16:49:46 26 4
gpt4 key购买 nike

我试图制作一个可调整大小的图像,但无法弄清楚这一点。
当我使用

UIImage *bgImage = [[UIImage imageNamed:@"logout-bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(50, 50, 50, 50)];
[bgImage drawInRect:boxRect];


它给出以下输出 enter image description here

而不是调整大小它会破坏图像。

但如果我使用

UIImage *bgImage = [[UIImage imageNamed:@"logout-bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(50, 50, 50, 50)];
CGContextDrawImage(context, boxRect, bgImage.CGImage);


它给出以下输出 enter image description here
现在而不是调整其拉伸(stretch)图像的大小。

我已经通过互联网搜索但无法解决我的问题。谁能帮我。请注意我不想在任何 subview 中添加这个。

我的原始图像是(它具有透明度,为什么它从中间看起来是灰色的) enter image description here

最佳答案

那么问题就在插图上。您的原始图像是 100x100 像素 并且您将插图设置为 50像素对于四个边缘中的任何一个(顶部,左侧,底部,右侧)。这意味着您的图像现在是这样切片的:

enter image description here

你注意到有什么问题吗?没有什么可重复的!

因此,如果我们渲染图像,我们会得到:

enter image description here

现在我们真正想要的是制作插图,以便我们保持圆角并重复其他所有内容。像这样的东西(这是 20px 插图):

enter image description here

这当然在渲染时给了我们想要的结果:)

enter image description here

所以唯一需要改变的是:

UIImage *bgImage = [[UIImage imageNamed:@"logout-bg"]
resizableImageWithCapInsets:UIEdgeInsetsMake(20, 20, 20, 20)];

关于iphone - 绘制矩形 :boxRect vs CGContextDrawImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17037635/

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