我喜欢在UIImageView中裁剪图像。你能否给我提供对我有用的完整源代码。在iPhone中裁剪图像
0
A
回答
2
我用来裁剪在相同的UIImageView
图像1)存储图像uiimageview
2)采取相同的UIImageView并将其存储为UIImage的
3)裁剪图像,并恢复它
下面的代码将有助于
- (IBAction为)setCropItem:(ID)发送者 {
UIGraphicsBeginImageContext(self.view.bounds.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *finishedPicForCrop = UIGraphicsGetImageFromCurrentImageContext();
CGImageRef imageRef = CGImageCreateWithImageInRect([finishedPicForCrop CGImage], CGRectMake(0, 45, 320, 420));
UIImage *img = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
[firstImageView removeFromSuperview];
secondImageView = [[UIImageView alloc] initWithImage:img];
[secondImageView setFrame:CGRectMake(0, 0, 320, 460)];
scrollView.contentSize = secondImageView.bounds.size;
[scrollView addSubview:secondImageView];
}
2
它可以帮助你
UIImage* whole = [UIImage imageNamed:@"whole.jpg"]; //I know this image is 300x300
CGImageRef cgImg = CGImageCreateWithImageInRect(whole.CGImage, CGRectMake(x, y, 100, 100));
UIImage* part = [UIImage imageWithCGImage:cgImg];
UIImageView* Croppedimage = [[UIImageView alloc] initWithImage:part];
和下面的链接更加有用
how to crop image in to pieces programmatically
好运
1
若y你需要一个UI控件来裁剪图像尝试SSPhotoCropperViewController。这是一个自定义视图控制器,它提供了一个简单,可配置且易于使用的用户界面,用于在iPhone应用程序中裁剪和缩放照片。
1
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{
// get touch event
UITouch *touch = [[event allTouches] anyObject];
StartPoint = [touch locationInView:touch.view];
if (Img_Screen!=nil) {
[Img_Screen removeFromSuperview];
Img_Screen=nil;
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
// get touch event
UITouch *touch = [[event allTouches] anyObject];
EndPoint = [touch locationInView:touch.view];
[self finishedTouchInside];
}
-(void)finishedTouchInside{
CGFloat width=EndPoint.x-StartPoint.x;
CGFloat hieght=EndPoint.y-StartPoint.y;
CGRect myImageRect = CGRectMake(StartPoint.x, StartPoint.y, width, hieght);
Img_Screen= [[UIImageView alloc] initWithFrame:myImageRect];
CGImageRef imageRef = CGImageCreateWithImageInRect([imgView.image CGImage], myImageRect);
// or use the UIImage wherever you like
[Img_Screen setImage:[UIImage imageWithCGImage:imageRef]];
CGImageRelease(imageRef);
[self.view addSubview:Img_Screen];
imageViewNew.image=[UIImage imageWithCGImage:imageRef];
}
这里u能在ImageView的裁剪和裁剪图像将在ImageViewNew在显示
相关问题
- 1. iPhone - TTPhotoViewController裁剪图像
- 2. 如何在iPhone SDK中裁剪图像?
- 3. 如何在iPhone中裁剪图像?
- 4. iPhone:如何在ios5中裁剪图像
- 5. 如何在iPhone中裁剪图像
- 6. WinRT中的裁剪/裁剪图像
- 7. 在android中裁剪图像
- 8. 在Java中裁剪图像
- 9. 在Matlab中裁剪图像
- 10. 在HTML5中裁剪图像
- 11. 在Richfaces中裁剪图像
- 12. 在matlab中裁剪图像
- 13. 在android中裁剪图像
- 14. 在CSS中裁剪图像
- 15. 在opencv中裁剪图像
- 16. 在PHP中裁剪图像
- 17. 在Java中裁剪图像
- 18. 在wordpress中裁剪图像
- 19. 裁剪图像
- 20. 裁剪图像
- 21. 裁剪图像
- 22. iphone UIbezierpath不规则图像裁剪
- 23. 星形的裁剪图像iphone
- 24. 无法剪裁/裁剪图像
- 25. 图像裁剪AVCaptureSession图像
- 26. 笨裁剪图像
- 27. 图像裁剪c#
- 28. Itext7 - 裁剪图像
- 29. WPF图像裁剪
- 30. html5图像裁剪
感谢您的建议最后我在上周六找到了答案。它与上面的代码是一样的我使用CGImageCreateWithImageInRect()来裁剪图像,但我用来将uiimageview存储为uiimage,然后在相同的uiimageview中裁剪图像 – NandaKumar 2011-06-13 07:39:21
welcome&very good :-) – NIKHIL 2011-06-13 08:04:54