• <i id='hzCZM'><tr id='hzCZM'><dt id='hzCZM'><q id='hzCZM'><span id='hzCZM'><b id='hzCZM'><form id='hzCZM'><ins id='hzCZM'></ins><ul id='hzCZM'></ul><sub id='hzCZM'></sub></form><legend id='hzCZM'></legend><bdo id='hzCZM'><pre id='hzCZM'><center id='hzCZM'></center></pre></bdo></b><th id='hzCZM'></th></span></q></dt></tr></i><div id='hzCZM'><tfoot id='hzCZM'></tfoot><dl id='hzCZM'><fieldset id='hzCZM'></fieldset></dl></div>
  • <legend id='hzCZM'><style id='hzCZM'><dir id='hzCZM'><q id='hzCZM'></q></dir></style></legend>

        <bdo id='hzCZM'></bdo><ul id='hzCZM'></ul>

      <tfoot id='hzCZM'></tfoot>

        <small id='hzCZM'></small><noframes id='hzCZM'>

        从 MTKView 创建的 UIImage 导致颜色/不透明度差异

        UIImage created from MTKView results in color/opacity differences(从 MTKView 创建的 UIImage 导致颜色/不透明度差异)
        <i id='uMvRE'><tr id='uMvRE'><dt id='uMvRE'><q id='uMvRE'><span id='uMvRE'><b id='uMvRE'><form id='uMvRE'><ins id='uMvRE'></ins><ul id='uMvRE'></ul><sub id='uMvRE'></sub></form><legend id='uMvRE'></legend><bdo id='uMvRE'><pre id='uMvRE'><center id='uMvRE'></center></pre></bdo></b><th id='uMvRE'></th></span></q></dt></tr></i><div id='uMvRE'><tfoot id='uMvRE'></tfoot><dl id='uMvRE'><fieldset id='uMvRE'></fieldset></dl></div>
          <tbody id='uMvRE'></tbody>

      1. <small id='uMvRE'></small><noframes id='uMvRE'>

        <tfoot id='uMvRE'></tfoot>

        <legend id='uMvRE'><style id='uMvRE'><dir id='uMvRE'><q id='uMvRE'></q></dir></style></legend>

              • <bdo id='uMvRE'></bdo><ul id='uMvRE'></ul>

                  本文介绍了从 MTKView 创建的 UIImage 导致颜色/不透明度差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当我将 MTKView 的内容捕获到 UIImage 中时,生成的图像看起来质量不同,如下所示:

                  When I capture the contents of an MTKView into a UIImage, the resulting image looks qualitatively different, as shown below:

                  我用来生成 UIImage 的代码如下:

                  The code I use to generate the UIImage is as follows:

                  let kciOptions = [kCIContextWorkingColorSpace: CGColorSpace(name: CGColorSpace.sRGB)!,
                                           kCIContextOutputPremultiplied: true,
                                           kCIContextUseSoftwareRenderer: false] as [String : Any]
                  let lastDrawableDisplayed = self.currentDrawable! // needed to hold the last drawable presented to screen
                  drawingUIView.image = UIImage(ciImage: CIImage(mtlTexture: lastDrawableDisplayed.texture, options: kciOptions)!)
                  

                  由于我不修改 ciImage 方向 (.orient(CGImagePropertyOrientation.downMirrored)),因此生成的图像是颠倒的,如上图所示.我保留镜像方向,以便指出两个图像捕获之间的颜色差异.

                  Since I don't modify the ciImage orientation (.oriented(CGImagePropertyOrientation.downMirrored)) the resulting image is upside down, as shown in the image above. I leave the mirrored orientation as is so I can point out the color differences between the two image captures.

                  无论我如何更改 kciOptions 参数(例如,甚至将色彩空间更改为灰度),我都没有看到生成的 UIImage 有任何变化,它看起来比原始图像更暗淡/不饱和.有人对我如何准确地将我在 MTKView 上绘制的内容捕获到 UIImage 有任何建议吗?任何建议将不胜感激.

                  No matter how I change the kciOptions parameters, (say, even changing the colorspace to grayscale) I'm not seeing any changes in the resulting UIImage, which appears much more dim/desaturated than the original. Does anybody have any suggestions for how I can accurately capture what I'm drawing on MTKView to an UIImage? Any suggestions would be much appreciated.

                  以下是我的 MTKView 设置,可能证明是相关的:

                  Below are my MTKView settings which may prove relevant:

                  let renderPipelineDescriptor = MTLRenderPipelineDescriptor()
                  renderPipelineDescriptor.vertexFunction = vertexProgram
                  renderPipelineDescriptor.sampleCount = self.sampleCount
                  renderPipelineDescriptor.colorAttachments[0].pixelFormat = MTLPixelFormat.bgra8Unorm
                  renderPipelineDescriptor.colorAttachments[0].isBlendingEnabled = true
                  renderPipelineDescriptor.colorAttachments[0].rgbBlendOperation = .add
                  renderPipelineDescriptor.colorAttachments[0].alphaBlendOperation = .add
                  renderPipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .sourceAlpha         renderPipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha            renderPipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .sourceAlpha              renderPipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha
                  self.isOpaque = false // makes MTKView bg transparent
                  

                  推荐答案

                  你的 CGColorSpace.sRGB 但你的 renderPipelineDescriptor 的 pixelFormat 是 .bgra8Unorm.尝试将该行更改为:

                  Your CGColorSpace is .sRGB but your renderPipelineDescriptor's pixelFormat is .bgra8Unorm. Try changing that line to:

                  renderPipelineDescriptor.colorAttachments[0].pixelFormat = MTLPixelFormat.bgra8Unorm_srgb
                  

                  这篇关于从 MTKView 创建的 UIImage 导致颜色/不透明度差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Can`t copy file from bundle to documents directory in iOS(无法将文件从捆绑包复制到 iOS 中的文档目录)
                  How to copy a quot;Dictionaryquot; in Swift?(如何复制“字典在斯威夫特?)
                  Swift - How to mutate a struct object when iterating over it(Swift - 迭代结构对象时如何对其进行变异)
                  How to copy text to clipboard/pasteboard with Swift(如何使用 Swift 将文本复制到剪贴板/粘贴板)
                  Swift Cannot invoke #39;find#39; with an argument list of type #39;([Score], Score)#39; where Score is a struct(Swift 无法使用类型为“([Score],Score)的参数列表调用“find,其中 Score 是一个结构)
                  Draggable UIImageView Partially Transparent amp; Irregular Shaped(可拖动的 UIImageView 部分透明 amp;不规则形状)
                  <tfoot id='R2rfm'></tfoot>

                    1. <legend id='R2rfm'><style id='R2rfm'><dir id='R2rfm'><q id='R2rfm'></q></dir></style></legend>
                    2. <i id='R2rfm'><tr id='R2rfm'><dt id='R2rfm'><q id='R2rfm'><span id='R2rfm'><b id='R2rfm'><form id='R2rfm'><ins id='R2rfm'></ins><ul id='R2rfm'></ul><sub id='R2rfm'></sub></form><legend id='R2rfm'></legend><bdo id='R2rfm'><pre id='R2rfm'><center id='R2rfm'></center></pre></bdo></b><th id='R2rfm'></th></span></q></dt></tr></i><div id='R2rfm'><tfoot id='R2rfm'></tfoot><dl id='R2rfm'><fieldset id='R2rfm'></fieldset></dl></div>

                        <bdo id='R2rfm'></bdo><ul id='R2rfm'></ul>
                        • <small id='R2rfm'></small><noframes id='R2rfm'>

                              <tbody id='R2rfm'></tbody>