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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:03:36+00:00 2026-06-12T01:03:36+00:00

I am using the following code to convert the contents of a UIView to

  • 0

I am using the following code to convert the contents of a UIView to a PNG image:

UIGraphicsBeginImageContext(myView.bounds.size);
[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

This works fine. If the UIView is 500 pixels high, and I’d like to generate two images (one of the top half and one of the bottom half), how would I go about doing this?

Any help would be greatly appreciated.

  • 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-12T01:03:37+00:00Added an answer on June 12, 2026 at 1:03 am

    There are a few ways you could do this. One way is to draw it into one big image, then make two sub-images:

    static UIImage *halfOfImage(UIImage *fullImage, CGFloat yOffset) {
        // Pass yOffset == 0 for the top half.
        // Pass yOffset == 0.5 for the bottom half.
    
        CGImageRef cgImage = fullImage.CGImage;
        size_t width = CGImageGetWidth(cgImage);
        size_t height = CGImageGetHeight(cgImage);
        CGRect rect = CGRectMake(0, height * yOffset, width, height * 0.5f);
    
        CGImageRef cgSubImage = CGImageCreateWithImageInRect(cgImage, rect);
        UIImage *subImage = [UIImage imageWithCGImage:cgSubImage scale:fullImage.scale
            orientation:fullImage.imageOrientation];
        CGImageRelease(cgSubImage);
        return subImage;
    }
    
    ...
        UIGraphicsBeginImageContext(myView.bounds.size);
        [myView.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        UIImage *topHalfImage = halfOfImage(viewImage, 0);
        UIImage *bottomHalfImage = halfOfImage(viewImage, 0.5f);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code to convert contents in Editor(Ajax control) to pdf,
I'm using the following code (using namespace std) to convert contents of a file
I am using the following code to convert an NSString to an NSDate :
Within a for loop, I'm using the following code to convert from one date
I am using the following code fragment in z3 4.0 to convert a formula
I have the following code to convert the type of the matrix using cv::Mat.convertTo()
I am using TimeStamp class to convert seconds into Day,Hours,Minutes,Seconds. I used following code
I'm using the following code to convert an Excel to a datatable using EPPlus:
Using following code I try to get updated list of checkbuttons' corresponding text values,
I using following code: var search = 'test'; if ($('#sku').find(search) ){ //alert(search); $(document).find(search).css('color','red'); <TABLE>

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.