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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:45:13+00:00 2026-06-15T01:45:13+00:00

In overriding a UIView drawRect, I draw the main image with CGContextDrawImage . Over

  • 0

In overriding a UIView drawRect, I draw the main image with CGContextDrawImage. Over it I need to draw another image (with a multiply blend mode), so I actually need to draw over it.

This second image needs to be prepares since it’s generated dynamically (it has to be masked, may be different size and so), so in the end I need to generate it. How can I get a second context where I can draw and mask this second image before applying it over the main one with? If I draw on the current context, it gets directly drawn no the main one before I can mask it.

- (void) drawRect:(CGRect)rect
{
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    CGContextDrawImage(ctx, CGRectMake(0, 0, rect.size.width, rect.size.height), [UIImage imageNamed:@"actionBg.png"].CGImage);

    // prevent the drawings to be flipped
    CGContextTranslateCTM(ctx, 0, rect.size.height);
    CGContextScaleCTM(ctx, 1.0, -1.0);

    // generate the overlay
    if ([self isActive] == NO && self.fullDelay != 0) { // TODO: remove fullDelay check!
        int segmentSize = (ACTION_SIZE / [self fullDelay]);

        for (int i=0; i<[self fullDelay]; i++) {
            float alpha = 0.9 - (([self fullDelay] * 0.1) - (i * 0.1));
            [[UIColor colorWithRed:120.0/255.0 green:14.0/255.0 blue:14.0/255.0 alpha:alpha] setFill];

            if (currentDelay > i) {
                CGRect r = CGRectMake(0, i * segmentSize, ACTION_SIZE, segmentSize);
                CGContextFillRect(ctx, r);
            }
            [[UIColor colorWithRed:1 green:1 blue:1 alpha:0.3] setFill];
            CGRect line = CGRectMake(0, (i * segmentSize) + segmentSize - 1 , ACTION_SIZE, 1);
            CGContextFillRect(ctx, line);
        }

        UIImage *overlay = UIGraphicsGetImageFromCurrentImageContext();
        UIImage *overlayMasked = [TDUtilities maskImage:overlay withMask:[UIImage imageNamed:@"actionMask.png"]];
    }
}

Here overlayMasked now contains the correct image, but since I’ve prepared it using the main context, its is not all messed. Thanks

Thanks

  • 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-06-15T01:45:15+00:00Added an answer on June 15, 2026 at 1:45 am

    You can create a bitmap context using either UIGraphicsBeginImageContextWithOptions or CGBitmapContextCreate. After you’re finished drawing in the bitmap context, you can get an image using UIGraphicsGetImageFromCurrentImageContext or CGBitmapContextCreateImage (as appropriate), and then release the context using either UIGraphicsEndImageContext or CGContextRelease.

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

Sidebar

Related Questions

I am trying to draw an image into a UIView subclass overriding drawRect. This
I'm subclassing UIView to make a custom view by overriding drawRect:. I need to
I'm overriding the drawRect: method in a custom UIView, and I'm doing some custom
According to Apple's docs, Subclasses need not override -[UIView drawRect:] if the subclass is
Reading through the documentation, it's not clear to me if overriding a UIView's drawRect
I'm trying to copy a UIView with some properties. The UIView is overriding the
I'm overriding the draw method of CCLayerColor to draw a border, but the color
When overriding the baseadapter on an android listview, you have to implement this method
When overriding drawRect I've found that the coordinates there use 0,0 as the upper
Normal overriding would work this way: class Fruit { public: string color(); }; string

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.