Draw selected UIImage areas

I have a UIImage containing an image with all the linkage of the smaller images in the image (essentially an image strip containing sprites). I would like to draw one sprite on the area of ​​my UIView.

I cannot find a way to draw only part of the UIImage on the view. Is there a way that does this?

+7
iphone uiview uiimage
source share
3 answers

I think you can search for CGImageCreateWithImageInRect () . You can get CGImage from UIImage with the same name .

EDIT: Another option that exists in 2014, which was not in 2009, SpriteKit . Depending on what you can do, you need a sprite sheet for this, which can be useful.

+8
source share

I wrote the UIImage category for handling sprites. Check this out, http://reecon.wordpress.com/2011/11/19/uiimage-sprite-additions-objective-c/ may be useful

As noted earlier, this category is based on CGImageCreateWithImageInRect() , but makes the process of extracting sprites from a single sprite sheet much more convenient and faster .

Link to git hub page: https://github.com/r3econ/UIImage-Sprite-Additions

You can also install using cocoa pods.

+3
source share

Yes you can with quartz.

There is a tutorial here that shows how to take a UIImage and mask part of it.

http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html

Here is the code from this page (if for some reason it doesn’t work)

 - (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage { CGImageRef maskRef = maskImage.CGImage; CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef), CGImageGetHeight(maskRef), CGImageGetBitsPerComponent(maskRef), CGImageGetBitsPerPixel(maskRef), CGImageGetBytesPerRow(maskRef), CGImageGetDataProvider(maskRef), NULL, false); CGImageRef masked = CGImageCreateWithMask([image CGImage], mask); return [UIImage imageWithCGImage:masked]; } 
+2
source share

All Articles