- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
这是背景图
这是标志
我们如何在 Swift 中制作这样的图像?
更新
现在我设法将 Logo 用作 mask 并得到类似这样的东西,
有什么办法可以把mask反转过来吗?
这是我的代码
let logo = UIImage(named: "logo")!
let mask = CALayer()
mask.contents = logo.CGImage
mask.frame = mImageView.layer.bounds
mImageView.layer.mask = mask
最佳答案
您可以使用 UIBezierPath 以编程方式完成此操作:
// lets create a view and an image for testing
let picture = UIImage(data: try! Data(contentsOf: URL(string: "http://i.stack.imgur.com/Xs4RX.jpg")!))!
// lets create a view and an image for testing
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: picture.size.width, height: picture.size.height))
imageView.image = picture
// now a layer for the mask
let maskLayer = CAShapeLayer()
// a path for the logo
let maskPath = CGMutablePath()
// create your logo path (I've added this circle to represent your logo path)
maskPath.addEllipse(in: CGRect(x: imageView.frame.midX - 150, y: imageView.frame.midY - 150, width: 300, height: 300))
// you will need a rectangle that covers the whole image area to intersect with your logo path
maskPath.addRect(CGRect(x: 0, y: 0, width: picture.size.width, height: picture.size.height))
// add the mask to your maskLayer
maskLayer.path = maskPath
// choose the fill rule EvenOdd
maskLayer.fillRule = kCAFillRuleEvenOdd
// add your masklayer to your view
imageView.layer.mask = maskLayer
imageView
如果您需要使用图像并以编程方式反转 Logo 的 alpha,您可以使用 kCGBlendModeDestinationOut 执行以下操作:
import UIKit
extension UIImage {
func masked(with image: UIImage, position: CGPoint? = nil, inverted: Bool = false) -> UIImage? {
let position = position ??
CGPoint(x: size.width.half - image.size.width.half,
y: size.height.half - image.size.height.half)
defer { UIGraphicsEndImageContext() }
UIGraphicsBeginImageContextWithOptions(size, false, scale)
draw(at: .zero)
image.draw(at: position, blendMode: inverted ? .destinationOut : .destinationIn, alpha: 1)
return UIGraphicsGetImageFromCurrentImageContext()
}
}
let picture = UIImage(data: try! Data(contentsOf: URL(string: "http://i.stack.imgur.com/Xs4RX.jpg")!))!
let logo = UIImage(data: try! Data(contentsOf: URL(string: "https://www.dropbox.com/s/k7vk3xvcvcly1ik/chat_bubble.png?dl=1")!))!
let view = UIView(frame: UIScreen.main.bounds)
view.backgroundColor = .blue
let iv = UIImageView(frame: UIScreen.main.bounds)
iv.contentMode = .scaleAspectFill
iv.image = picture.masked(with: logo, inverted: true)
view.addSubview(iv)
关于ios - 如何在 Swift 中以编程方式从另一个图像中剪切 Logo (png 图像)的形状?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30907448/
我有 2 个视频文件(input.mp4,leadout.mp4)和一个图像(watermark.png)。我需要将第一个视频剪切到 54 秒,添加水印,然后将其与第二个视频合并。 我实现了这个调用
在 VBA 中,您可以在剪切和粘贴后直接进行复制和粘贴。我之所以问,是因为 for 循环中的 If 语句需要剪切一行数据,然后直接在下面复制该行。当我运行代码时,它会执行该剪切,但不会执行副本。我在网
我想在剪切/粘贴事件触发后调用函数。 例如,当用户通过键盘或鼠标(带有上下文菜单)在编辑器中剪切/粘贴时,我想计算用户输入的字符数。 用户执行剪切/粘贴后有什么方法可以调用我们自己的函数吗? 最佳答案
抱歉,标题不准确,但实际上我正在尝试简化方法: Docker service ls 变成这个: Docker service ls cutted 尝试使用-f,但不起作用。 也许有一些grep / s
我有一个带有三角形的彩色噪声正方形。 现在,我希望多边形像圣诞节的“ cookies 切割器”一样减少这种噪音。导致被多边形路径包围的三角形噪声。 如何裁剪与多边形边框重叠的所有像素,然后将其另存为
我正在 Prolog 中开发一个谓词,它有可能在它结束之前终止。 出于这个原因,我正在寻找类似于 return; 的命令。 (C++)。我用了 cut !但我怀疑它的字面意思以及它是否确实做了什么re
我的代码如下所示: ServiceHandler sh = new ServiceHandler(); // Making a request to url and g
在 Linux(Raspbian 发行版)中,我试图提取文件名的日期部分,当我直接将其输入终端时,该文件名有效(见下文)。 $ file1="access_point20140821.csv" $ e
我正在使用 vuetify,我想制作一个可滚动的 stepper在对话框中。 这是一个代码笔 https://codepen.io/anon/pen/OqWQdy 我在 v-stepper-items
我有一个小测试站点,其中一个 div 的宽度减小到 50%,当我们单击按钮时另一个 div 出现。这是我的 codepen 当您单击该按钮时,图像会调整大小。因为我正在使用:background-si
我必须编写一个脚本文件来剪切以下列并将其粘贴到新 .arff 文件中同一行的末尾。我想文件类型无关紧要。 当前文件: 63,male,typ_angina,145,233,t,left_vent_hy
如何拦截此类事件? 当用户尝试将一些文本粘贴到我的 EditText 中时,我需要添加一些逻辑我知道我可以使用 TextWatcher 但这个入口点对我不利,因为我只在粘贴的情况下需要拦截,而不是每次
我有一个简单的自定义无边框 NSWindow 子类,它具有圆角矩形形状。 在此窗口的内容 View 中,我添加了一个 NSScrollView。 如何让 NSScrollView 将其文档 View
所以这是我的代码,但是每次尝试剪切字符串“words”都失败了,它只是用 jsoup 收到的整个文本执行 TextView。 我只想剪切字符串的前 x 个单词。 public class main e
Action Bar Select All/Cut/Copy not showing for EditText in Alert dialog(picture 2),请帮助 编辑:代码是
如何检测 tinymce 上的右键单击删除?我通过 onPaste 事件检测到粘贴事件,但我卡在剪切删除和复制上。我知道有 onContextMenu 事件,但似乎没有保存菜单项的函数或变量。 有什么
我有两个 JTextAreas 并且想要实现剪切、复制和粘贴菜单项。我知道 JTextArea.cut 和其他方法,但无法弄清楚如何确定用户在何处(在哪个 JTextArea 中)选择了文本和/或放置
我想在两侧“剪切”我的页面,如下所示: http://i.stack.imgur.com/ngZrp.jpg 演示:https://jsfiddle.net/r2g0eyxf/3/ #left {
我有一个绝对位于另一个元素之上的元素。问题是背景元素有一点 JS 可以根据鼠标的移动在 Y 轴上旋转。不幸的是,我在 Safari 中发现了一个在 Firefox 或 Chrome 中没有出现的问题。
我正在编写一个脚本,在该脚本中,我采用名片设计并使用它生成一张纸,上面有十张卡片,以匹配打印临时卡片的模板。这里最棘手的部分是出血;它们会在中间重叠,所以我需要为每个都制作剪贴蒙版。 我想出了一个系统
我是一名优秀的程序员,十分优秀!