- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
提供的是:带向下箭头图像的绿色气泡(绿色气泡图像已经有边框,所以我不需要绘制它)和中心照片。我需要在照片周围绘制白色边框 + 圆角这是我到目前为止的代码:
let rect = CGRect(origin: .zero, size: CGSize(width: 60, height: 67))
let width = CGFloat(50)
let borderWidth: CGFloat = 1.0
let imageRect = CGRect(x: 5, y: 5, width: width, height: width)
let bubbleImg = #imageLiteral(resourceName: "pinGreen")
UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0)
let context = UIGraphicsGetCurrentContext()
bubbleImg.draw(in: rect)
let path = UIBezierPath(roundedRect: imageRect.insetBy(dx: borderWidth / 2, dy: borderWidth / 2), cornerRadius: width/2)
context!.saveGState()
path.addClip()
image.draw(in: imageRect)
context!.restoreGState()
UIColor.purple.setStroke()
path.lineWidth = borderWidth
path.stroke()
let roundedImage = UIGraphicsGetImageFromCurrentImageContext();
let img = roundedImage?.cgImage!
UIGraphicsEndImageContext();
这是结果
谁能帮我解决这个问题?有没有办法从 xib 文件中设计并获取这种类型的图像?
最佳答案
我会告诉你最简单的方法:
绿色气泡图像需要 imageView1,照片需要 imageView2(宽度 = 高度)。他们的中心是一样的。
imageView2 的角半径等于其框架宽度/2。
将imageView2层的边框颜色设置为白色,边框宽度约为5px。不要忘记设置 maskToBounds=true
。
请尝试。
关于Swift:使用 UIGraphicsBeginImageContextWithOptions 绘制图像和边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41714996/
所以我有一个函数可以拍摄两张图像并将它们组合起来。也许图像太大,因为当我尝试使用 2 个较小的图像时,效果很好,但我不确定。所以我用相机拍了一张照片,然后尝试从相册中打开它。我选择图像并使用此函数将其
我正在努力适应THIS问题与视网膜显示器一起使用。以下是我如何弄清楚如何使用 UIGraphicsBeginImageContext 的视网膜图形。 if (UIGraphicsBeginImageC
我只是进行签名并使用 imageMask 进行保存。实际上,imageMask 渲染正确,但主签名行为异常,如其中的 2 行。这是我的代码。 UIGraphicsBeginImageContextWi
在使用 UIGraphicsBeginImageContextWithOptions 截屏时,是否有隐藏特定按钮(IBAction)的方法? 我正在使用下面的代码: // Define the di
我有这行代码来截取 uiview 的屏幕截图: - (UIImage *)imageWithView:(UIView *)view { UIImage *viewImage = nil
一段时间以来,我一直在努力使用这种方法。我正在另一张图片上绘制头像。用户图片我想成为一个圆圈,但我似乎无法弄清楚如何。用户图片是 UIImage 而不是 UIImageView。如果它是 ImageV
我使用下面的函数来渲染图像,但返回的图像底部有不需要的边框。 public func renderTextOnView(view: UIView) -> UIImage? { UIGraphi
我对 UIGraphicsBeginImageContextWithOptions 和线程有点困惑,因为根据 UIKit Function Reference UIGraphicsBeginImage
在我正在开发的应用程序中,客户输入一些个人信息并在屏幕上的一个框中签名。然后我以编程方式截取完整 View 并将其转换为 base64。 这工作正常,但是,由于图像的大小,将其转换为 base64 并
问题 我正在使用 UIGraphicsBeginImageContextWithOptions 将屏幕截图保存到 UIImage 中。虽然这有效,但生成的 UIImage 缺少任何阴影和渐变。 如何让
我需要绘制这样的图像 提供的是:带向下箭头图像的绿色气泡(绿色气泡图像已经有边框,所以我不需要绘制它)和中心照片。我需要在照片周围绘制白色边框 + 圆角这是我到目前为止的代码: let rect =
我正在开发 iOS 应用程序。它目前仅适用于 iOS 4,因为我多次使用以下方法:“UIGraphicsBeginImageContextWithOptions”。此方法仅在 iOS 4 中可用,因此
我正在我的 SKScene 中绘制一条路径以显示我的对象的轨迹。一切正常,我可以绘制所有点的路径并将其添加到场景中。当我尝试打印我的场景时,问题发生了,除了路径之外的所有内容都出现了。我哪里做错了?
我正在使用 SDWebImage 下载缩略图。在使用 - (UIImage *)imageManager:(SDWebImageManager *)imageManager transformDown
我有一个函数 UIGraphicsBeginImageWithContextWithOptions()和 UIGraphicsEndImageContext( ,但该函数已经传递了一个名为“conte
所以我有这段代码来创建一个 UIImage: UIGraphicsBeginImageContextWithOptions(border.frame.size, YES, 0); [border.la
我正在寻找一种解决方案来将 UIView(及其 subview )保存为图像到设备照片库。我希望输出图像的大小为 1024 x 1024。UIView 将始终是一个正方形,因此 subview 将适合
使用此类方法并创建纯色 UIImage 会比创建纯色 png 更快吗? + (UIImage*) imageWithColor:(UIColor*)color size:(CGSize)size {
在绘制到屏幕外缓冲区时,我很难让 Image Insets 正常工作。 在 UIImage 上直接使用 resizableImageWithCapInsets: setImage: into a bu
我曾经使用以下代码调整图像大小,它过去在比例因子方面工作得很好。现在使用 Swift 3 我无法弄清楚为什么不考虑比例因子。图像已调整大小但未应用比例因子。你知道为什么吗? let layer = s
我是一名优秀的程序员,十分优秀!