我喜歡在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 SDK中裁剪圖像?
- 2. iPhone:如何在ios5中裁剪圖像
- 3. 如何在iPhone中裁剪圖像?
- 4. 在PHP中裁剪圖像
- 5. 在matlab中裁剪圖像
- 6. 在android中裁剪圖像
- 7. 在Java中裁剪圖像
- 8. 在Matlab中裁剪圖像
- 9. 在Richfaces中裁剪圖像
- 10. 在HTML5中裁剪圖像
- 11. 在CSS中裁剪圖像
- 12. 裁剪圖像
- 13. 裁剪圖像
- 14. 星形的裁剪圖像iphone
- 15. 無法剪裁/裁剪圖像
- 16. WPF圖像裁剪
- 17. html5圖像裁剪
- 18. WPF圖像裁剪
- 19. 笨裁剪圖像
- 20. 裁剪android圖像
- 21. GWT圖像裁剪
- 22. Silverlight圖像裁剪
- 23. 裁剪YUV圖像
- 24. raphael.js裁剪圖像
- 25. 問題在裁剪圖像
- 26. java中的圖像裁剪
- 27. 裁剪圖像的中心
- 28. 從UIImageView中裁剪圖像
- 29. 從URL中裁剪圖像
- 30. R中的裁剪圖像
感謝您的建議最後我在上週六找到了答案。它與上面的代碼是一樣的我使用CGImageCreateWithImageInRect()來裁剪圖像,但我用來將uiimageview存儲爲uiimage,然後在相同的uiimageview中裁剪圖像 – NandaKumar 2011-06-13 07:39:21
welcome&very good :-) – NIKHIL 2011-06-13 08:04:54