Mangiare Senza Glutine disponibile su App Store

Per altre informazioni scrivi a fabriziocaldarelli@negusweb.it

Ridimensionare una UIImage

Da Programmazione Software.

Vengono passati come parametri l'immagine di partenza ed il fattore di scala. L'immagine risultante è in autorelease, quindi non va rilasciata.

  1. - (UIImage*)imageScale:(UIImage *)imageToScale factor:(CGFloat)factor;
  2. {
  3. 	CGSize size = CGSizeMake( imageToScale.size.width*factor, imageToScale.size.height*factor );
  4.  
  5. 	// Create a bitmap graphics context
  6. 	// This will also set it as the current context
  7. 	UIGraphicsBeginImageContext(size);
  8.  
  9. 	// Draw the scaled image in the current context
  10. 	[imageToScale drawInRect:CGRectMake(0, 0, size.width, size.height)];
  11.  
  12. 	// Create a new image from current context
  13. 	UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
  14.  
  15. 	// Pop the current context from the stack
  16. 	UIGraphicsEndImageContext();	
  17.  
  18. 	return scaledImage;
  19. }
Strumenti personali
hobby
approfondimenti