ios - 在代码中创建图像并将其显示到 UIImageView
问题描述
我正在尝试创建图像。通过检查大小,我可以看到该图像已创建。但我无法将该图像分配为 UIImageView 的图像属性。请帮忙。
let imageRenderer=UIGraphicsImageRenderer(size: self.view.bounds.size)
book = imageRenderer.image { c in
let ctx=c.cgContext
ctx.setStrokeColor(UIColor.black.cgColor)
ctx.setLineWidth(5)
let x=self.view.bounds.maxX
let y=self.view.bounds.maxY
ctx.move(to: CGPoint(x:x/16,y:x/8))
ctx.addLine(to: CGPoint(x: x/2, y: x/4))
ctx.addLine(to: CGPoint(x: x-x/16, y: x/8))
ctx.addLine(to:CGPoint(x: x-x/16, y: y-x/8))
ctx.addLine(to: CGPoint(x: x/2, y: y-x/16))
ctx.addLine(to: CGPoint(x: x/16, y: y-x/8))
ctx.closePath()
}
self.image.image = book!
解决方案
您只需添加线条但不为它们绘制颜色。
你可以通过调用为他们痛苦的颜色
ctx.strokePath()
紧随其后(在封闭内)
ctx.closePath()
您可以在此处阅读更多信息
https://developer.apple.com/documentation/coregraphics/cgcontext/1454490-strokepath
推荐阅读
- azure - Azure EventGrid 在哪里保留等待传递的消息?
- angularjs - AngularJS v1.8.0 ng-selected 选项不起作用
- javascript - 为什么 $.get 总是以空警报的形式出现?
- sql - 存储取决于天数的数据的最佳方法是什么?
- javascript - 使用 ViewBag 在 ASP.NET MVC 中选择的下拉列表?
- angular - Angular 动态过滤具有多个条件的 RxJS 可观察对象
- php - 在 1 个函数 Laravel 中使用 2 个翻译有问题吗?
- python - 错误 - UNWILLING_TO_PERFORM - 在 AD ldap 中使用 python 代码更改用户密码
- laravel - 使用作曲家安装时出现laravel错误
- javascript - cordova-plugin-ionic-webview,无法使用 Javascript document.cookie (iOS) 设置 cookie