- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 Swift 中重新编写我的 Android 应用程序以启动 iOS,但我已经遇到了障碍......
Android 应用程序是关于基于 ColorMatrix 总和的图像处理......即制作灰度图像的下一个矩阵:
float[] bwMatrix = {
0f, 1f, 0f, 0f, 0f,
0f, 1f, 0f, 0f, 0f,
0f, 1f, 0f, 0f, 0f,
0f, 0f, 0f, 1f, 0f,
0f, 0f, 0f, 0f, 1f};
import UIKit
dynamic var colorMatrix : CIFilter?
class editionViewController: UIViewController {
@IBOutlet weak var editionImageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
let fileManager = FileManager.default
let imagePath = (self.getDirectoryPath() as NSURL).appendingPathComponent("editionImg0.png")
let urlString: String = imagePath!.absoluteString
if fileManager.fileExists(atPath: urlString) {
let originalImage = UIImage (contentsOfFile: urlString)
let liaImage = originalImage?.liaFilter()
editionImageView.image = liaImage
}
}
func getDirectoryPath() -> NSURL {
let path = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString).appendingPathComponent("tempImages")
let url = NSURL (string: path)
return url!
}
}
extension UIImage {
//Lia filter
func liaFilter() -> UIImage? {
let inImage = CIImage(image: self)
colorMatrix?.setDefaults()
colorMatrix?.setValue(inImage, forKey: "inputImage")
colorMatrix?.setValue(CIVector(x: 0, y: 1, z: 0, w: 0), forKey: "inputRvector")
colorMatrix?.setValue(CIVector(x: 0, y: 1, z: 0, w: 0), forKey: "inputGvector")
colorMatrix?.setValue(CIVector(x: 0, y: 1, z: 0, w: 0), forKey: "inputBvector")
colorMatrix?.setValue(CIVector(x: 0, y: 0, z: 0, w: 1), forKey: "inputAvector")
let outCIImage = (colorMatrix?.outputImage)
return UIImage (ciImage: outCIImage!) //HERE is the crash
/*
if let outCIImage = colorMatrix?.outputImage {
return UIImage (ciImage: outCIImage)
}
return nil
*/
}
}
最佳答案
colorMatrix 属性是 nil
因为您从未正确初始化它。
删除 dynamic var colorMatrix: CIFilter?
从您的 Controller 并使用下面的代码。
class editionViewController: UIViewController {
@IBOutlet weak var editionImageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
if let image = UIImage(named: "myImage.png") {
editionImageView.image = image.liaFilter()
}
}
}
extension UIImage {
//Lia filter
func liaFilter() -> UIImage {
let inImage = CIImage(image: self)
let rgbVector = CIVector(x: 0, y: 1, z: 0, w: 0)
let aVector = CIVector(x: 0, y: 0, z: 0, w: 1)
dynamic let colorMatrix = CIFilter(name: "CIColorMatrix")
if colorMatrix != nil {
colorMatrix?.setDefaults()
colorMatrix?.setValue(inImage, forKey: kCIInputImageKey)
colorMatrix?.setValue(rgbVector, forKey: "inputRVector")
colorMatrix?.setValue(rgbVector, forKey: "inputGVector")
colorMatrix?.setValue(rgbVector, forKey: "inputBVector")
colorMatrix?.setValue(aVector, forKey: "inputAVector")
if let output = colorMatrix?.outputImage, let cgImage = CIContext().createCGImage(output, from: output.extent) {
return UIImage(cgImage: cgImage)
}
}
return self
}
}
关于ios - Swift 中 ColorMatrix 的亮度、饱和度和对比度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60140691/
我想将一些颜色值从众所周知的 HSL 转换为鲜为人知的 HSLum 怎么做? hsl(0, 1.0, 0.5) - rgb red is hslum(0, 1.0., 0.54) hsl(120,
有没有办法在 android 中获取有关屏幕类型的信息?我想知道我使用的设备是 amoled/ips/tft 还是获得屏幕的最大亮度,不是相对亮度,而是尼特或坎德拉/cm2 的亮度 最佳答案 与设备的
我的 iPhone 应用程序使用 AVFoundation 的 AVCaptureSession 从摄像头捕获实时数据。我能够在运行时访问它的委托(delegate)方法中的数据并从中创建图像。它可以
我正在使用带有 AVFoundation 的前置摄像头开发镜像应用程序。我已经完成了向 UIView 显示相机屏幕。但是如何调整亮度?代码是这样的: -(void)AVCaptureInit {
我有一个 android 应用程序,我正在使用下面的代码增加图像的亮度。但这非常慢,所以有没有人知道在 android 中增强 ImageView 的图像亮度的快速方法。请记住,这是提高 ImageV
我想做的是创建一个代码,以便当用户移动 SeekBar 时,它会更改手机的亮度(随着移动)并将其设置为手机的 MAIN 设置。我已经剪掉了我认为是问题所在的部分代码.. public void onP
我制作了一个手电筒应用程序,可以通过按钮打开相机的 LED 灯。如果可能的话,我希望能够使用搜索栏更改 LED 灯的亮度。 如果这有帮助的话,这是我按钮中的代码: public class Flash
我正在开发一款编辑视频的应用。录制视频时没有问题,因为最初我会设置所有设置,如饱和度、亮度、对比度等。 但问题在于录制的视频。我无法更改已录制视频的所有上述属性。 任何人请告诉我他的问题的解决方案。
这个问题在这里已经有了答案: I do not want to inherit the child opacity from the parent in CSS (18 个答案) 关闭 7 年前。
我有两个网络摄像头(都是罗技 C615)。我想以一种方式调整网络摄像头,使它们在相同的环境中拍摄出几乎相同的照片。 (原因是我想将此图像渲染到 occulus rift 上)。 我正在使用 OpenC
我有一个使用 CSS 创建的圆圈,如下所示: .circle { width: 40px; height: 40px; -moz-border-radius: 50px;
我正在尝试过滤位图图像以增加或减少色相、饱和度和亮度值。 我的代码运行良好,但速度很慢。 我在内存中锁定了两个位图,原始源和当前目标。用户可以移动各种 trackbar 控件来修改每个值,然后将其转换
我有一个 android 应用程序,我在其中使用 android 相机拍照。经过一番努力后,我设法在我想要的地方和我想要的方式拍摄照片。最后的问题是质量图片。 当我的预览开始时,一切看起来都非常清晰和
是否有c++函数或opencv库可以计算给定8*8 block 或总图像亮度的平均对数?我的目标是计算平均亮度并将其存储回 block 中。另外,有没有另一种适合人类视觉系统的科学方法来计算整体亮度或
寻找答案 2 周。我有一个工具可以直接在网络浏览器中调整图像的对比度和亮度,并使用 CSS3 属性来显示结果。但我还应该将这些修改应用于服务器端的原始 JPG,并将其输出回用户。 我该怎么做?我正在使
我正在尝试将对比度和亮度应用于内存中的位图,但我完全迷路了。目前我正在尝试使用 Magick++ 来完成它,但如果其他 API 之一能更好地工作,我会洗耳恭听。我设法找到 Magick::Image:
我正在尝试使用 MCP3002 ADC 和电位计来控制 PWMLED 亮度列表。 我的问题是,当我运行我的脚本时,除了连接到 MCP3002 ADC 的电位器之外,一切都按预期运行,它不会在我调整旋钮
假设我们有一张在光线不足的情况下拍摄的照片。图像比平时更暗,但仍可识别。 现在我们想让它更亮,让它看起来像是在充足的光照条件下拍摄的。 我们应该将图像转换为 YUV 并调整 Y channel (亮度
嗨,我的客户有一个新要求,他需要在他的网站上添加字体大小增加和对比度/亮度、声音控制。 因此,在单击任何一个图像时,都会出现一个 slider ,他可以从中执行相应的操作。 我如何使用 jquery
我在游戏中使用 SVG 文件,我想为其添加透明度和亮度效果。所以我想要的是 Sprite 变得越来越透明,直到看不见。这看起来比刚刚消失的 Sprite 平滑得多。这还允许在白屏变得不那么透明然后又变
我是一名优秀的程序员,十分优秀!