Je souhaite autoriser un utilisateur à sélectionner des pixels sur l'écran et créer une nouvelle image à partir des pixels créés. Y a-t-il une classe spécifique pour cela ou est-ce que je devrais le faire tout seul?Comment rogner des images dans iPhone SDK?
1
A
Répondre
1
vous devriez jeter un oeil à http://www.hive05.com/2008/11/crop-an-image-using-the-iphone-sdk/
1
- (UIImage*)getCroppedImage
{
CGRect rect = self.cropView.frame;
CGRect drawRect = [self cropRectForFrame:rect];
UIImage *croppedImage = [self imageByCropping:self.image toRect:drawRect];
return croppedImage;
}
- (UIImage *)imageByCropping:(UIImage *)image toRect:(CGRect)rect
{
if (UIGraphicsBeginImageContextWithOptions)
{
UIGraphicsBeginImageContextWithOptions(rect.size,
/* opaque */ NO,
/* scaling factor */ 0.0);
}
else
{
UIGraphicsBeginImageContext(rect.size);
}
// stick to methods on UIImage so that orientation etc. are automatically
// dealt with for us
[image drawAtPoint:CGPointMake(-rect.origin.x, -rect.origin.y)];
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
-(CGRect)cropRectForFrame:(CGRect)frame
{
NSAssert(self.contentMode == UIViewContentModeScaleAspectFit, @"content mode must be aspect fit");
CGFloat widthScale = self.bounds.size.width/self.image.size.width;
CGFloat heightScale = self.bounds.size.height/self.image.size.height;
float x, y, w, h, offset;
if (widthScale<heightScale) {
offset = (self.bounds.size.height - (self.image.size.height*widthScale))/2;
x = frame.origin.x/widthScale;
y = (frame.origin.y-offset)/widthScale;
w = frame.size.width/widthScale;
h = frame.size.height/widthScale;
} else {
offset = (self.bounds.size.width - (self.image.size.width*heightScale))/2;
x = (frame.origin.x-offset)/heightScale;
y = frame.origin.y/heightScale;
w = frame.size.width/heightScale;
h = frame.size.height/heightScale;
}
return CGRectMake(x, y, w, h);
}
Questions connexes
- 1. Enregistrer des photos/images dans l'application? iPhone SDK
- 2. chargement paresseux des images dans UITableView iPhone SDK
- 3. Nouvelles images introuvables dans le SDK iPhone
- 4. iPhone - Comment faites-vous un rectangle redimensionnable pour rogner des images?
- 5. iPhone SDK: UIWebView pour arrêter le chargement/téléchargement des images
- 6. iPhone SDK: interagir avec les images
- 7. Détermination des dimensions des images dans l'iPhone SDK
- 8. Comment puis-je télécharger des images personnalisées dans ma barre d'onglets dans le SDK iPhone?
- 9. Comment redimensionner et rogner efficacement des images dans une application ASP.NET?
- 10. Comment afficher l'image UIImageJPEGRepresentation dans iphone sdk
- 11. comment rogner l'image dans codeigniter?
- 12. php gd: quand je rogner des images par php quelques images sortent smushed
- 13. L'évaluation des éléments dans plist iphone sdk
- 14. stocker des images dans l'application iPhone
- 15. Sauvegarder des images dans la photothèque Iphone
- 16. Script dans iPhone SDK
- 17. webservice Dans Iphone SDK?
- 18. créer plusieurs images voir comme l'application photo iphone sdk
- 19. Jouer des sons dans le SDK iPhone?
- 20. Gestion des erreurs dans Xcode, iPhone SDK
- 21. contournant UIImagePicker dans iphone sdk
- 22. Comment désinstaller Iphone sdk?
- 23. iPhone sdk - nom des propriétaires?
- 24. iPhone SDK - UIScrollView & UIPageControl
- 25. discuter dans iphone sdk?
- 26. police dans iphone sdk?
- 27. Précharger des images dans l'application iPhone?
- 28. iOS4 SDK et iPad et @ 2x images
- 29. comment implémenter la recherche dans iphone sdk
- 30. iPhone SDK élément aperçu