gpt4 book ai didi

ios - 无法识别的选择器发送到实例 - 如何修复 : Error Loading picture from photo album

转载 作者:行者123 更新时间:2023-11-28 10:40:13 25 4
gpt4 key购买 nike

尝试从相册加载图片时出现以下错误,我不确定为什么:无法识别的选择器发送到实例下面是我的代码,下面是我的错误堆栈的一部分:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFNumber extent]: unrecognized selector sent to instance 0x60000022d440' *** First throw call stack: ( 0 CoreFoundation 0x000000010efe21e6 __exceptionPreprocess + 294 1 libobjc.A.dylib 0x000000010d1e9031 objc_exception_throw + 48 2 CoreFoundation 0x000000010f063784 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 3 CoreFoundation 0x000000010ef64898 ___forwarding_ + 1432 4 CoreFoundation 0x000000010eff5d28 forwarding_prep_1_ + 120 5 CoreImage 0x000000010daecf17 -[CISepiaTone outputImage] + 152

请在下面找到我的源代码:

import UIKit
import CoreImage

class ViewController: UIViewController, UINavigationControllerDelegate {
//outlet for image to be filtered
@IBOutlet weak var imageToFilter: UIImageView!

//outlet for slider to manipulate intensity as slider is dragged
@IBOutlet weak var filterIntensity: UISlider!

//property to store UIImage containing the image selected by user from photo album
var currentImage: UIImage!

//context from CoreImage Framework to handle rendering of the image for Wakanda Filter
var imageContext: CIContext!

//CoreImage Filter to store filters selected by the user
var currentImageFilters: CIFilter!

override func viewDidLoad() {
super.viewDidLoad()

//objects of coreContext and coreFilterd
imageContext = CIContext()
currentImageFilters = CIFilter(name: "CISepiaTone")

//title to appear on nav
title = "Wakanda Filter"
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(importPictureFromAlbum))
}

//action to update UI when user increases or decreases intensity
@IBAction func intensityValueChanged(_ sender: UISlider) {
processImageWithFilter()
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
guard let imageSelected = info[UIImagePickerControllerEditedImage] as? UIImage else {
return
}

dismiss(animated: true)

currentImage = imageSelected

//setting imported image as value to Filter object then manipulating
let initialImageForFilters = CIImage(image: currentImage)
currentImageFilters.setValue(initialImageForFilters, forKey: kCIInputImageKey)

//calling on method to process the image
processImageWithFilter()
}

func processImageWithFilter(){
currentImageFilters.setValue(filterIntensity.value, forKey: kCIInputImageKey)
if let computerGeneratedImage = imageContext.createCGImage(currentImageFilters.outputImage!, from: currentImageFilters.outputImage!.extent){
let processedImage = UIImage(cgImage: computerGeneratedImage)
self.imageToFilter.image = processedImage
}
}
}

extension ViewController: UIImagePickerControllerDelegate {
//objective c method to control method for selector how to import picture from album
@objc func importPictureFromAlbum(){
//creating an object of UIImagePickerController class (will allow editing of images too by modifying Info.plist
let imagePicker = UIImagePickerController()

//allow editing of the image
imagePicker.allowsEditing = true

//assigning delegate
imagePicker.delegate = self

present(imagePicker, animated: true)
}
}

最佳答案

CISepiaTone 过滤器需要两个参数:

inputImage: A CIImage object whose display name is Image.

inputIntensity: An NSNumber object whose attribute type is CIAttributeTypeScalar and whose display name is Intensity.

你的错误来自这一行:

currentImageFilters.setValue(filterIntensity.value, forKey: kCIInputImageKey)

将值更改为图像或将键更改为 kCIInputIntensityKey

鉴于您之前设置了图像,您可能想更改此行的 key 。

currentImageFilters.setValue(filterIntensity.value, forKey: kCIInputIntensityKey)

关于ios - 无法识别的选择器发送到实例 - 如何修复 : Error Loading picture from photo album,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50869092/

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