Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Take a look at UIGraphicsBeginImageContext, UIGraphicsGetImageFromCurrentContext and UIImage's drawInRect: methods.
 
Take a look at UIGraphicsBeginImageContext, UIGraphicsGetImageFromCurrentContext and UIImage's drawInRect: methods.

I don't think that'll work. The draw in rect documentation says

Draws the entire image in the specified rectangle, scaling it as needed to fit

So you'd end up with loads of small copies of the entire image instead of the image chopped into tiles. drawAtPoint would work, I think, as it does not scale the image. That said the CG function I linked to seems easier...
 
I don't think that'll work. The draw in rect documentation says
So you'd end up with loads of small copies of the entire image instead of the image chopped into tiles. drawAtPoint would work, I think, as it does not scale the image. That said the CG function I linked to seems easier...
Thanks, I will try.
 
I don't think that'll work. The draw in rect documentation says



So you'd end up with loads of small copies of the entire image instead of the image chopped into tiles. drawAtPoint would work, I think, as it does not scale the image. That said the CG function I linked to seems easier...

The image's scale depends on the CGSize of the CGRect passed to the drawRect: method. Basically, drawAtPoint: is a special case of drawInRect:.
 
By the way, is it possible to show a animated GIF file in UIImageView? I used the same code to load gif89a file, but it seems like no animation...
 
I did it, but no animation.

You may well have to use a UIWebView. UIImageView seems to expect an array of images to animate with. UIImage does not seem to support the concept of multiple animation frames within an image so it's likely that what you are trying to do simply doesn't work.
 
You may well have to use a UIWebView. UIImageView seems to expect an array of images to animate with. UIImage does not seem to support the concept of multiple animation frames within an image so it's likely that what you are trying to do simply doesn't work.
I found a AnimatedGif class on Internet, do you think which way is better? UIWebView or AnimatedGif?
 
I pulled this from some code I've been working on. It will split an image into individual tiles and return those in an array.

In this object I have some instance variables you'll have to make you own assumptions for; rows, cols, containerCellHeight, containerCellWidth. Those are decisions made before this code is called.

I used CGImageCreateWithImageInRect to get my tiles.

Code:
- (NSMutableArray *) setUpCellsUsingImage: (UIImage *) masterImage
{
	NSMutableArray * cellArray;
	NSInteger row, col;
	CGImageRef tempSubImage;
	CGRect tempRect;
	CGFloat yPos, xPos;	
	UIImage * aUIImage;
	
	cellArray = [[NSMutableArray new] autorelease];
	
	for (row=0; row < rows; row++) {
		yPos = row * containerCellHeight;
		for (col=0; col < cols; col++) {
			xPos = col * containerCellWidth;

			tempRect = CGRectMake(xPos, yPos, containerCellWidth, containerCellHeight);		
			
			tempSubImage = [COLOR="Red"]CGImageCreateWithImageInRect[/COLOR](masterImage.CGImage, tempRect);

			aUIImage = [UIImage imageWithCGImage: tempSubImage];
			[cellArray addObject: aUIImage];

			aUIImage = nil;
			CGImageRelease(tempSubImage);
			
		}
	}
	
	return cellArray;
}
 
I pulled this from some code I've been working on. It will split an image into individual tiles and return those in an array.

In this object I have some instance variables you'll have to make you own assumptions for; rows, cols, containerCellHeight, containerCellWidth. Those are decisions made before this code is called.

I used CGImageCreateWithImageInRect to get my tiles.

Code:
- (NSMutableArray *) setUpCellsUsingImage: (UIImage *) masterImage
{
	NSMutableArray * cellArray;
	NSInteger row, col;
	CGImageRef tempSubImage;
	CGRect tempRect;
	CGFloat yPos, xPos;	
	UIImage * aUIImage;
	
	cellArray = [[NSMutableArray new] autorelease];
	
	for (row=0; row < rows; row++) {
		yPos = row * containerCellHeight;
		for (col=0; col < cols; col++) {
			xPos = col * containerCellWidth;

			tempRect = CGRectMake(xPos, yPos, containerCellWidth, containerCellHeight);		
			
			tempSubImage = [COLOR="Red"]CGImageCreateWithImageInRect[/COLOR](masterImage.CGImage, tempRect);

			aUIImage = [UIImage imageWithCGImage: tempSubImage];
			[cellArray addObject: aUIImage];

			aUIImage = nil;
			CGImageRelease(tempSubImage);
			
		}
	}
	
	return cellArray;
}
Thanks, I will try to test it.

By the way, I am not sure if I have to post a new thread, I want to know if it is possible to slice a video? how about performance if show 16 tiles video if it is possible?
 
I'm just starting to look into video. Perhaps the AVFoundation stuff will work. It looks like AVCaptureVideoDataOutput may be your in for processing the frames.
 
Forgot to mention a couple of things regarding the tile split code.

The image I'm passing has been resized so that the split aligns with pixels, not on fractions. I found this easier to fix a problem when drawing the tiles onto my the underlying view. I'd get odd grid lines on a device, but not the emulator.

If I recall right, UIImage and CGImage have different origins. So in my case, reconstructing the tiles into a view got me tiles out of vertical order. That is just something to watch out for.
 
Forgot to mention a couple of things regarding the tile split code.

The image I'm passing has been resized so that the split aligns with pixels, not on fractions. I found this easier to fix a problem when drawing the tiles onto my the underlying view. I'd get odd grid lines on a device, but not the emulator.

If I recall right, UIImage and CGImage have different origins. So in my case, reconstructing the tiles into a view got me tiles out of vertical order. That is just something to watch out for.
Can you tell me which way you draw the tiles, I post new thread
https://forums.macrumors.com/threads/1076891/
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.