菜鸟教程小白 发表于 2022-12-12 12:41:50

ios - 如何将 UIImage 转换为位图 int 数组 (rgb565)


                                            <p><p>我需要将我的 UIImage 传递给一个图像处理算法,该算法采用 <code>rgb565</code> 格式的位图的 int 数组。</p>

<p>稍后,它返回经过图像处理的 int 数组,我需要将其转换回 UIImage。</p>

<p>看看它的语法:</p>

<pre><code>int* ImageProcessingAlgorithm(int bitmapArray[], int width, int height);
</code></pre>

<p>我搜索了很多地方,但似乎都没有 UIImage-to-int-array 以及反之亦然的转换。我发现最近的是 <a href="http://paulsolt.com/2010/09/ios-converting-uiimage-to-rgba8-bitmaps-and-back/" rel="noreferrer noopener nofollow">this</a>但这涉及 char 数组 - 我尝试将它用于我的目的,但我不断收到 UIKit 库函数中的各种访问错误和泄漏。也许我没有正确管理内存或 int-to-unsigned char-to-int 转换中的一些错误。</p>

<p>我可以处理那部分,但我仍然不确定它是否适合我的图像处理算法格式(<code>rgb565</code>)。</p>

<p>我是图像处理的新手,图像处理算法对我来说是一个黑盒,所以我只需要可以传入和传出该算法的整数数组。 </p>

<p>我可以肯定的是,该算法返回的数组元素数量与它作为输入的数量相同 - 即输入和输出数组代表相同数量的图像像素。</p>

<p>提前感谢您的帮助。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>正如我所想,<code>CGBitmapContextGetData</code> 函数返回一个指向数组的 void 指针,它可以转换为任何类型的数组指针。重要的是以后的处理。</p>

<p>这里是 <a href="https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGBitmapContext/Reference/reference.html#//apple_ref/doc/uid/TP30000947-CH1g-CGBitmapContextGetData" rel="noreferrer noopener nofollow">documentation</a> .</p>

<p>可以使用此技术转换为 rgb565,取自 <a href="https://stackoverflow.com/a/9069480/1506363" rel="noreferrer noopener nofollow">here</a> :</p>

<pre><code>R5 = ( R8 * 249 + 1014 ) &gt;&gt; 11;
G6 = ( G8 * 253 +505 ) &gt;&gt; 10;
B5 = ( B8 * 249 + 1014 ) &gt;&gt; 11;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何将 UIImage 转换为位图 int 数组 (rgb565),我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/17766039/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/17766039/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何将 UIImage 转换为位图 int 数组 (rgb565)