Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to grab a subimage from a UIImage. I've looked around for a similar question, to no avail.

I know the range of pixels I want to grab - how can I return this subimage, from an existing image?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
346 views
Welcome To Ask or Share your Answers For Others

1 Answer

This should help: http://iphonedevelopment.blogspot.com/2010/11/drawing-part-of-uiimage.html

This code snippet is creating a category of UIImage but the code should be easily modified to work without it being a category.

A shorter way of doing the same thing is the following:

CGRect fromRect = CGRectMake(0, 0, 320, 480); // or whatever rectangle

CGImageRef drawImage = CGImageCreateWithImageInRect(image.CGImage, fromRect);
UIImage *newImage = [UIImage imageWithCGImage:drawImage];
CGImageRelease(drawImage);

Hope this helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...