Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7442051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:07:02+00:00 2026-05-29T11:07:02+00:00

I am developing a coloring book application for iPad (iOS4+). The application should allow

  • 0

I am developing a coloring book application for iPad (iOS4+). The application should allow to color only one area of an image at a time.

I mean, if users touches anywhere on the screen and starts moving the finger, the color should be applied to only those pixels that are contained within the same area as the first touch point. For example, if users touches center of the left image and starts moving finger all over the image he should get something like the right image.

enter image description here

I think that one of the solutions for the task might be to create a mask in shape of the area touched and then apply this mask to the image before doing farther modifications. But, honestly, I have no idea where to start.

Could you please tell me how can I create such a mask?

The solution might use Core Graphics and Open GL.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:07:03+00:00Added an answer on May 29, 2026 at 11:07 am

    As @Till suggested, I implemented queued flood fill algorithm. I had to do some optimizations to keep memory consumption and speed of execution in reasonable limits.

    I don’t use the algorithm to really fill an image. I use the algorithm to create masks:

    • Create an array of mask bytes (image_width * image_height bytes)
    • Fill the whole array with 0xFF values
    • Use flood-fill algorithm to find all pixels within the area and coordinates of the rectangle containing the area.
    • For each found pixel set corresponding value in array of mask bytes to 0
    • Create another (smaller array) of mask bytes and copy part (defined by the calculated rectangle) of the array of mask bytes to the new array.
    • Create a mask using following code
        NSData* maskData = // construct NSData from mask bytes
    
        CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData((CFMutableDataRef)maskData);
    
        int width = maskRight - maskLeft + 1;
        int height = maskBottom - maskTop + 1;
        CGImageRef maskImage = CGImageMaskCreate(width, height, 8, 8, width, dataProvider, NULL, YES);
        CGDataProviderRelease(dataProvider);
    
    • You can use the mask later using code like the following
        CGContextSaveGState(context);
    
        CGContextTranslateCTM(context, 0.0, 768);
        CGContextScaleCTM(context, 1.0, -1.0);
    
        CGRect r = CGRectApplyAffineTransform(maskImageRect, CGContextGetCTM(context));
        CGContextClipToMask(context, r, maskImage);
    
        CGContextTranslateCTM(context, 0.0, 768);
        CGContextScaleCTM(context, 1.0, -1.0);
    
        // mask is setup, draw here 
    
        CGContextRestoreGState(context);
    

    Using this code you can create a mask of any shape. You can even create a semi-transparent mask if you want. To create a semi-transparent mask you need to set some values other than 0 in the array of mask bytes for transparent areas (0 – fully transparent, 255 – fully opaque).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When developing a new web based application which version of html should you aim
iam developing iPhone application that allow user to define stations near to him, so
Developing an HTML 5 application on new iPad's Mobile Safari iOS 5 that displays
Iam developing one application.In that i use the google api for getting the location
Iam developing one application.In that i use the google api for getting the location
iam developing one application.In that i use the search bar for search the data.But
Developing websites are time-consuming. To improve productivity, I would code a prototype to show
Developing a .NET WinForms application: how can I check if the window is in
Developing a heavily XML-based Java-application, I recently encountered an interesting problem on Ubuntu Linux.
Developing a C# .NET 2.0 WinForm Application. Need the application to close and restart

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.