drawing image out of a context

Discussion in 'iOS Programming' started by chhoda, Mar 10, 2010.

  1. chhoda macrumors 6502

    Oct 25, 2008
    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 ?

  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    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.

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

Share This Page