简体   繁体   中英

Bitmaps: How do I format my array of RGBA values to be converted into an image?

I have a float array "MyColors[100][4]" (4 because of rgb & a for each of MyColors) . I want to turn it into a bitmap to make a UIImage out of it. I've experimented with some code but really don't know what I'm doing. How can I make my 100x4 array into something a bitmap can use?

You could use CGImageCreate function . That creates a CGImageRef, which then can be used to create a UIImage:

UIImage *uiImage = [[UIImage alloc] initWithCGImage:cgImage];

CGImageCreate "provider" parameter (of type CGDataProviderRef) is a thing that provides the image data, so first you need to create that from your array. One example of using CGDataProviderCreateWithData is here .

It expects colors in a certain specified format. The supported formats are described here "Color Spaces and Bitmap Layout" . It seems that you can use floats if you premultiply colors with alpha, and use the kCGBitmapFloatComponents flag, but I would rather simplify it and just use integers instead for color components.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM