To create a blank image, use the width:height:depth:palette: class method of CgDeviceIndependentImage. The image data is initialized to all zeros. The following example shows how to create a 100-by-50 pixel gray-scale image with 8 bits per pixel. Because the palette specifies black for pixel value 0, the image is initially all black.The image attributes can be retrieved using the width, height, depth, palette, and data methods of CgDeviceIndependentImage. The extent method answers the width and height as a point.To modify a single pixel value, use the putPixel:y:pixelValue: method. This method takes the x- and y- coordinates of the pixel and stores the new pixel value at that location in the image.A more efficient way of modifying image data is to use the putPixels:y:width:pixels:startIndex: method, which modifies a horizontal line of pixels in a given scanline. The following code modifies the image data with the same result as the previous code, but is more efficient.Image data can be retrieved one pixel at a time using the getPixel:y: method. A horizontal line of pixels can be retrieved using getPixels:y:width:pixels:startIndex:. A new image can be copied from an area of an existing image using the getSubImage: method and passing it a rectangle. The getPixel: and putPixel: methods have getColor: and putColor: equivalents that answer and accept CgRGBColor objects rather than pixel values and use the image's palette to convert between colors and pixel values.
|