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?
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.