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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:47:49+00:00 2026-06-02T20:47:49+00:00

Since CGContextDrawImage can be quite expensive, I’m trying to minimize the amount of data

  • 0

Since CGContextDrawImage can be quite expensive, I’m trying to minimize the amount of data I’m giving it while I examine the pixel data. If I have two images and the CGRect of their intersection, can I get CGContextDrawImage to only draw the intersection of each independently (resulting in two CGContextRefs containing the intersection of one of the images)?

Here’s some code that doesn’t work, but should be close to what I need for one image…

    CGImageRef imageRef = [image CGImage];
    NSUInteger width = rectIntersect.size.width;
    NSUInteger height = rectIntersect.size.height;

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    unsigned char *rawData = (unsigned char*) calloc(height * width * 4, sizeof(unsigned char));
    NSUInteger bytesPerPixel = 4;
    NSUInteger bytesPerRow = bytesPerPixel * width;
    NSUInteger bitsPerComponent = 8;
    CGContextRef context = CGBitmapContextCreate(rawData, width, height,
                                                 bitsPerComponent, bytesPerRow, colorSpace,
                                                 kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
    CGColorSpaceRelease(colorSpace);

    // rectIntersect down here contains the intersection of the two images...
    CGContextDrawImage(context, rectIntersect, imageRef);
  • 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-02T20:47:51+00:00Added an answer on June 2, 2026 at 8:47 pm

    Well, you don’t need to draw them unless you really want a CGBitmapContext with them. Use CGImageCreateWithImageInRect() to create sub-images. This doesn’t necessarily require the frameworks to copy any image data. It may just reference the image data from the original. So, it can be quite efficient.

    If you really do need the images drawn into contexts, you can of course just draw the sub-images.

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

Sidebar

Related Questions

Since each thread has its own stack, its private data can be put on
Since I am developing an iOS >= 5.0 application, I am trying to change
Since now I have only used plugin for editing and the way I use
Since I have no errors I don't know if this is the right place
I'm trying since 5 hours now: - (void)drawRect:(CGRect)rect { // flip the wrong coordinate
since they have same rendering engine, this problem shows in both. it works great
Since CS3 doesn't have a web service component, as previous versions had, is there
Since Javascript does not have any functionality by itself to communicate over raw sockets
Since multiple requests can slow down the speed at which a site loads, I
Since trees are special kind of graphs or we can categorize trees in DAG(Directed

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.