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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:06:17+00:00 2026-06-04T05:06:17+00:00

After transferring a large image from a REST endpoint, I need to divide the

  • 0

After transferring a large image from a REST endpoint, I need to divide the image into a number of smaller image tiles.

The initial image is (for instance) 1024×1024, stored in an NSData; I need to create sub-image of size 256×256 (In this case, there will be 16 sub-images).

How would this be done? (I haven’t found any articles which even come close, but I assume it must be possible since most image editing software supports image cropping.)

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-04T05:06:20+00:00Added an answer on June 4, 2026 at 5:06 am
    @interface UIImage (Sprite)
    - (NSArray *)spritesWithSpriteSheetImage:(UIImage *)image spriteSize:(CGSize)size;
    - (NSArray *)spritesWithSpriteSheetImage:(UIImage *)image inRange:(NSRange)range spriteSize:(CGSize)size;
    @end
    
    
    
    
    @implementation UIImage (Sprite)
    
    -(NSArray *)spritesWithSpriteSheetImage:(UIImage *)image spriteSize:(CGSize)size {
        return [self spritesWithSpriteSheetImage:self inRange:NSMakeRange(0, lroundf(MAXFLOAT)) 
                                  spriteSize:size];
    }
    -(NSArray *)spritesWithSpriteSheetImage:(UIImage *)image 
                                inRange:(NSRange)range 
                             spriteSize:(CGSize)size {
    if (!image || CGSizeEqualToSize(size, CGSizeZero) || range.length == 0) 
        return nil;
    NSLog(@"%i %i", range.location, range.length);
    CGImageRef spriteSheet = [image CGImage];
    NSMutableArray *tempArray = [[[NSMutableArray alloc] init] autorelease];
    
    int width = CGImageGetWidth(spriteSheet);
    int height = CGImageGetHeight(spriteSheet);
    
    int maxI = width / size.width;
    int startI = 0;
    int startJ = 0;
    int length = 0;
    int startPosition = range.location;
    
    // Extracting initial I & J values from range info
    //
    if (startPosition != 0) {
        for (int k=1; k<=maxI; k++) {
            int d = k * maxI;
            if (d/startPosition == 1) {
                startI = maxI - (d % startPosition);
                break;
            }
            else if (d/startPosition > 1) {
                startI = startPosition;
                break;
            }
            startJ++;
        }
    }
    int positionX = startI * size.width;
    int positionY = startJ * size.height;
    BOOL isReady = NO;
    while (positionY < height) {
        while (positionX < width) {
            CGImageRef sprite = CGImageCreateWithImageInRect(spriteSheet, CGRectMake(positionX, positionY, size.width, size.height));
            [tempArray addObject:[UIImage imageWithCGImage:sprite]];
            CGImageRelease(sprite);
            length++;
            if (length == range.length) {
                isReady = YES;
                break;
            }
            positionX += size.width;
        }
        if (isReady) 
            break;
        positionX = 0;
        positionY += size.height;
    }
    return [NSArray arrayWithArray:tempArray];
      }
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm transferring images from a high-FPS camera into a memory buffer (a List), and
...after it retrieves all of it from MongoDB and transferring it over the network?
Basic idea of what im after.. On document ready copy classes from #box-one into
I am transferring a message from one emulator instance on a machine to another
I'm sending a very large string from one application to another on localhost using
I'm having difficulties registering an example XPCOM component into firefox from this example here:
I am transferring a database from one hosting provider to another. The current provider
I am writing remote desktop application. So I am transferring Images from one machine
I am transferring a large static website of 500+ pages to a Joomla installation
After highlighting text, I would like to obtain the paragraph in which the selected

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.