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 4555084
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:10:32+00:00 2026-05-21T17:10:32+00:00

I want to take a image (a brush) and draw it into a displayed

  • 0

I want to take a image (a brush) and draw it into a displayed image. I only want to affect the alpha of that image, and I need to export it later.

From what I’ve seen, most directions only really get into some costly looking operations that don’t pan out. ie they recommend you draw into an offscreen context, create a CGImage of the mask, and create a CGImageWithMask pretty much every time the brush is applied at all.

I already know this is costly because even just doing this and drawing into a context is rather rough for iPhone.

What I’d like to do is take the UIImage of an UIImageView, and manipulate it’s alpha channel directly. I also am not doing it pixel-by-pixel, but with a largish (20px radius) brush that has a softness of its own.

  • 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-21T17:10:33+00:00Added an answer on May 21, 2026 at 5:10 pm

    I would not use an UIImageView for this. A normal UIView is enough.

    Just put the Image into the layer with

    UIView *view = ...
    view.layer.contents = (id)image.CGImage;
    

    after that you can make parts of the image transparent by adding a mask to the layer

    CALayer *mask = [[CALayer alloc] init]
    mask.contents = maskimage.CGImage;
    view.layer.mask = mask;
    

    for a project I did something where I had a brush.png that you could use to reveal an image with a finger… my update mask function there was:

    - (void)updateMask {
    
        const CGSize size = self.bounds.size;
        const size_t bitsPerComponent = 8;
        const size_t bytesPerRow = size.width; //1byte per pixel
        BOOL freshData = NO;
        if(NULL == _maskData || !CGSizeEqualToSize(size, _maskSize)) {
            _maskData = calloc(sizeof(char), bytesPerRow * size.height);
            _maskSize = size;
            freshData = YES;
        }
    
        //release the ref to the bitmat context so it doesn't get copied when we manipulate it later
        _maskLayer.contents = nil;
        //create a context to draw into the mask
        CGContextRef context = 
        CGBitmapContextCreate(_maskData, size.width, size.height, 
                              bitsPerComponent, bytesPerRow,
                              NULL,
                              kCGImageAlphaOnly);
        if(NULL == context) {
            LogDebug(@"Could not create the context");
            return;
        }
    
        if(freshData) {
            //fill with mask with alpha == 0, which means nothing gets revealed
            CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
            CGContextFillRect(context, CGRectMake(0, 0, size.width, size.height));    
        }
    
        CGContextTranslateCTM(context, 0, self.bounds.size.height);
        CGContextScaleCTM(context, 1.0f, -1.0f);
    
        //Draw all the points in the array into a mask
        for (NSValue* pointValue in _pointsToDraw)
        {
            CGPoint point;
            [pointValue getValue:&point];
            //LogDebug(@"location: %@", NSStringFromCGPoint(point));
    
            [self drawBrush:[_brush CGImage] at:point inContext:context];
        }
        [_pointsToDraw removeAllObjects];
    
        //extract an image from it
        CGImageRef newMask = CGBitmapContextCreateImage(context);
    
        //release the context
        CGContextRelease(context);
    
        //now update the mask layer
        _maskLayer.contents = (id)newMask;
        //self.layer.contents = (id)newMask;
        //and release the mask as it's retained by the layer
        CGImageRelease(newMask);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I want to take an image that the user chooses from their photo
I want to be able to take an image that i have already captured
I want to take an image from the UIImagePickerController and put it on a
I am using WAMP. I want to take background image URL from my database
I have a grid where I want to take the text from that cell,
In my application i have Implement to take image from Gallery. In that gallery
In my project i want to take image from my iPhone camera and upload
I want to take the image from drawable folder but it should be in
I have splash.png and want that this image take all place on the screen
i have a requirement, i want to take URL of image from user and

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.