drawing image out of a context

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

  1. chhoda macrumors 6502

    Joined:
    Oct 25, 2008
    #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
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    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;
    }
     

Share This Page