Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chhoda

macrumors 6502
Original poster
Oct 25, 2008
285
1
Currently I am overriding drawrect Method to draw some lines etc to my view. I need similar drawing but to some rectangle and make a UIImage or CGIImage out of it. Can I ? any examples ?

--CH
 
This is an example of code that creates a UIImage outside of drawRect. You can do any kind of Core Graphics drawing after creating the image context.

Code:
UIImage* resizedImage(UIImage *inImage, CGRect thumbRect)
{
	UIGraphicsBeginImageContext(thumbRect.size);
	
	// Draw into the context, this scales the image
	[inImage drawInRect:CGRectMake(0, 0, thumbRect.size.width, thumbRect.size.height)];

	UIImage*	result = UIGraphicsGetImageFromCurrentImageContext();

	UIGraphicsEndImageContext();

	return result;
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.