我正在處理Camera Application用戶正在拍攝照片,但我想裁剪該圖像中的任何位置並將其發送到服務器。我怎樣才能做到這一點?如何在iphone中裁剪特定圖像
0
A
回答
3
退房此鏈接的詳細信息:
http://www.hive05.com/2008/11/crop-an-image-using-the-iphone-sdk/
Basic代碼:
- (UIImage*)imageByCropping:(UIImage *)imageToCrop toRect:(CGRect)rect
{
//create a context to do our clipping in
UIGraphicsBeginImageContext(rect.size);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
//create a rect with the size we want to crop the image to
//the X and Y here are zero so we start at the beginning of our
//newly created context
CGRect clippedRect = CGRectMake(0, 0, rect.size.width, rect.size.height);
CGContextClipToRect(currentContext, clippedRect);
//create a rect equivalent to the full size of the image
//offset the rect by the X and Y we want to start the crop
//from in order to cut off anything before them
CGRect drawRect = CGRectMake(rect.origin.x * -1,
rect.origin.y * -1,
imageToCrop.size.width,
imageToCrop.size.height);
//draw the image to our clipped context using our offset rect
CGContextDrawImage(currentContext, drawRect, imageToCrop.CGImage);
//pull the image from our cropped context
UIImage *cropped = UIGraphicsGetImageFromCurrentImageContext();
//pop the context to get back to the default
UIGraphicsEndImageContext();
//Note: this is autoreleased
return cropped;
}
2
我想我可以提供一個更好的解決方案到大量的代碼。
- (void)viewDidLoad
{
[super viewDidLoad];
// do something......
UIImage *croppedImage = [self imageByCropping:[UIImage imageNamed:@"SomeImage.png"] toRect:CGRectMake(10, 10, 100, 100)];
}
- (UIImage*)imageByCropping:(UIImage *)imageToCrop toRect:(CGRect)rect
{
CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage], rect);
UIImage *cropped = [UIImage imageWithCGImage:imageRef];
return cropped;
}
相關問題
- 1. 在iPhone中裁剪圖像
- 2. 如何在iPhone SDK中裁剪圖像?
- 3. 如何在iPhone中裁剪圖像?
- 4. iPhone:如何在ios5中裁剪圖像
- 5. 如何在iPhone中裁剪圖像
- 6. iPhone - TTPhotoViewController裁剪圖像
- 7. 如何在黑莓中裁剪特定形狀的圖像?
- 8. 裁剪圖像的特定部分
- 9. 如何在ImageMagick中統一裁剪/裁剪圖像?
- 10. WinRT中的裁剪/裁剪圖像
- 11. 如何裁剪DICOM圖像
- 12. 如何裁剪圖像
- 13. 如何裁剪圖像?
- 14. 如何在Qt中裁剪圖像?
- 15. 如何在android中裁剪圖像?
- 16. 如何在Android中裁剪圖像?
- 17. 如何在Monououch中裁剪圖像Xamarin
- 18. 如何在Cocos2d中裁剪圖像
- 19. 如何在Java中裁剪圖像?
- 20. 如何在android中裁剪圖像
- 21. 如何在codeigniter中裁剪圖像?
- 22. 如何在vb.net中裁剪圖像?
- 23. 如何在iOS中裁剪圖像
- 24. 如何在asp.net中裁剪tiff圖像
- 25. 如何在P5中裁剪圖像?
- 26. 如何在J2ME中裁剪圖像
- 27. 如何在iphone中裁剪圖像圈sdk
- 28. 在android中裁剪圖像
- 29. 在Java中裁剪圖像
- 30. 在Matlab中裁剪圖像
你應該接受一些答案....... – Robin
ü要這個...... [鏈接](http://img192.imageshack.us/img192/8930/customcropbox.jpg) – avinash
看到這個。我想你想要同樣的[鏈接](http://stackoverflow.com/questions/1971542/iphone-how-do-you-make-a-resizable-rectangle-for-cropping-images) – avinash