如何将具有双元素的数组转换为我可以使用的图像?
我正在将 XCode 与 Objective C 结合使用,我想知道如何将具有 double 类型元素的数组转换为可以在 xCode 中轻松使用的图像?
该数组定义如下:
double x [50][100];
另外,我不确定如何释放该变量 (x
)。我需要担心解除分配吗?
I'm using XCode with Objective C and I'm wondering how I can transform an array with elements of type double into an image I can work with easily in xCode?
The array is defined as follows:
double x [50][100];
Also, I'm not sure how to deallocate this variable (x
). Do I need to worry about deallocating it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些数字需要代表像素的组成部分。对于 RGB 颜色,每个像素需要 3 或 4 个分量(数字),具体取决于是否需要透明度 (alpha)。对于单色(灰度),您需要 1 或 2。对于 CMYK 颜色(用于打印),您需要 4 或 5。(实际上,我不确定您是否可以执行 CMYKA。)
此外,他们需要按规定的顺序进行。 RGB 颜色的常见顺序包括 RGBA(alpha 最后)和 ARGB(alpha 首先)。
最后,它们应该呈平面阵列。您可能会使用多维数组,但我不确定您是否可以依赖它。
满足所有这些要求后,您需要将数字数组传递给 CGImage 或 CGBitmapContext,具体取决于您正在做什么。这两个都是Core Graphics的一部分。
不,因为您没有动态分配它。未以其他方式声明的变量具有“自动存储持续时间”,这正是您所期望的,并且在您的声明中,整个数组都在变量中。
与这样的声明对比:
在该声明中,变量中只有一个指针;它指向的内存位于其他地方,并且可能会也可能不会自动管理,完全取决于分配的方式。
The numbers need to represent components of pixels. For RGB color, you'll want 3 or 4 components (numbers) per pixel, depending on whether or not you want transparency (alpha). For monochrome (grayscale), you'll want 1 or 2. For CMYK color (for printing), you'll want 4 or 5. (I'm not sure whether you can do CMYKA, actually.)
Furthermore, they need to be in a defined order. Common orders for RGB color include RGBA (alpha last) and ARGB (alpha first).
Finally, they should be in a flat array. You may get away with a multidimensional array, but I'm not sure you can rely on that.
Once you've satisfied all of that, you'll need to pass the array of numbers to either CGImage or CGBitmapContext, depending on what you're doing. Both of these are part of Core Graphics.
No, because you didn't dynamically allocate it. A variable not otherwise declared has “automatic storage duration”, which means exactly what you'd expect, and in your declaration, the entire array is in the variable.
Contrast with a declaration like this:
In that declaration, only a pointer is in the variable; the memory it points to lies elsewhere, and may or may not be automatically managed, depending entirely on how that was allocated.