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

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

iphone - Return a subimage from a UIImage

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

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

1 Answer

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...