2

I need in UIImage created from my colors (for example, i need in image 1x1 pixel with black color).

I've got array:

unsigned char *color[] = {0, 0, 0, 1};

How can i create UIImage from this array ?

I've try

 unsigned char *bytes[4] = {0,0,0,1};
 NSData *data = [NSData dataWithBytes:bytes length:4];
 UIImage *img = [UIImage imageWithData:data];

but this method has no result...

2 Answers 2

3

You'll want to create a bitmap context (using CGBitmapContextCreate()), and draw into that. This requires using CoreGraphics. Then take your context and use CGBitmapContextCreateImage() to create an CGImageRef out of it. Finally, use +[UIImage imageWithCGImage:] to convert that CGImageRef to a UIImage.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, i'm trying this, but i have problem with alpha channel. I've got picture with ALPHA channel, and i try change color (for example: from yellow to green) and i think alpha must keep... I've try this: milytia.org/paste/117 when brush is RGBA bytes array. When i run it i have artefacts on my generated image (on ALPHA place)...
1

Thank you, all!

This is solved my problem.

http://www.iphonedevsdk.com/forum/iphone-sdk-development/23525-cgimagecreate-alpha.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.