Iphonesdk boundries checking for coloring
im creating and app where user already have an image (with different objects) without colors, i have to check the object and the开发者_开发技巧n color with respected color with the touch on that objects. how should i do this. can anyone help me.
I would say that that is non-trivial. I can only give hints since I have not done such an app yet.
First, you need to convert the image into a CGImageRef
, for example by doing [uiimage_object CGImage]
.
Next you need convert the CGImageRef into array of pixel colors. You can follow the tutorial at http://www.fiveminutes.eu/iphone-image-processing/ for sample code. But for your app you need to convert the array into two dimension based on image width and height.
Then, use the coordinate of the user touch to access the exact pixel color value from the array. Next you read off the color values of the surrounding pixels and determine if color is similar to the touched pixel or not (you might need to read some wikipedia articles etc on doing the color comparison). If the color is similar, change the color to the one you want. Recurse until the surrounding color is different (i.e. you hit the boundary).
When you are finished modifying the pixel color value array, you need to convert the array back into CGImageRef
using CGImageCreate
function. Then you convert back to UIImage
using [UIImage imageWithCGImage:imageref]
.
Now you are on your own to implement the steps into code. It would be unreasonable if you expect me to code all that for you, wouldn't it?
精彩评论