【问题标题】:Applying Filters to image swap height and width in swift快速将过滤器应用于图像交换高度和宽度
【发布时间】:2019-11-18 00:00:59
【问题描述】:

目前我正在开发一个应用程序,我可以在其中捕获照片并将过滤器应用于照片。过滤器应用完美,但应用过滤器后,新图像大小高度宽度与捕获的图像交换。像这样

我无法弄清楚我在哪里犯了错误

  let ciContext = CIContext(options: nil)
    let coreimg = CIImage(image: AppDelegate.captured_iamge!)
    let filter = CIFilter(name: CIFilterNames[indexPath.row])
    filter!.setDefaults()
    filter!.setValue(coreimg, forKey: kCIInputImageKey)
    let filtered_img_data = filter!.value(forKey: kCIOutputImageKey) as! CIImage
    let filtered_img_ref = ciContext.createCGImage(filtered_img_data, from: filtered_img_data.extent)
    let img = UIImage(cgImage: filtered_img_ref!)
    img_view.image = img

如果有人能帮忙就好了

【问题讨论】:

  • “更大”是指图像尺寸还是内存占用?
  • 图片尺寸

标签: uiimageview swift4 core-image cifilter


【解决方案1】:

这可能是因为您的输入图像的方向(纵向)与相机的自然方向(横向)不同。

如果您向UIImage 询问它的大小,它已经考虑了它的方向。然而,在引擎盖下,图像数据按来自相机的方式存储,这也是 Core Image 正在运行的内容。因此,在您的过滤器链中,图像正在丢失其方向信息。

我认为您可以通过在创建时将该信息传递给输出图像来解决此问题:

let inputImage = AppDelegate.captured_iamge!
//...
let img = UIImage(cgImage: filtered_img_ref!, scale: inputImage.scale, orientation: inputImage.orientation)

【讨论】:

    猜你喜欢
    • 2018-10-07
    • 2018-05-06
    • 2021-02-08
    • 2021-11-17
    • 1970-01-01
    • 1970-01-01
    • 2016-09-28
    • 2015-06-28
    • 1970-01-01
    相关资源
    最近更新 更多