2013-04-09 158 views
3

我有一個應用程序,我裁剪從camera.all拍攝的圖像很好。但裁剪後的圖像似乎模糊和拉伸。修剪圖像後圖像模糊?

CGRect rect = CGRectMake(20,40,280,200); 
UIGraphicsBeginImageContext(rect.size); 
CGContextRef context = UIGraphicsGetCurrentContext(); 

// translated rectangle for drawing sub image 
CGRect drawRect = CGRectMake(-rect.origin.x, -rect.origin.y,280,200); 

// clip to the bounds of the image context 
// not strictly necessary as it will get clipped anyway? 
CGContextClipToRect(context, CGRectMake(0, 0, rect.size.width, rect.size.height)); 

// draw image 
[image drawInRect:drawRect]; 

// grab image 
UIImage* croppedImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
CGSize size = [croppedImage size]; 
NSLog(@" = %@",NSStringFromCGSize(size)); 
NSData* pictureData = UIImagePNGRepresentation(croppedImage); 

有人可以幫我找出我要去哪裏嗎?

+0

你的意思是這個http://stackoverflow.com/questions/14645158/image-is-getting-拉伸和模糊後作物或此http://stackoverflow.com/questions/12109519/uiimage-showing-blur-after-cropping-in-iphone? – Joetjah 2013-04-09 14:40:47

+0

你能提供一個截圖嗎? – Undo 2013-04-09 14:43:27

+0

請檢查此:-http://stackoverflow.com/questions/15288092/how-to-crop-the-captured-image-before-saving-it-in-gallery-in-ios/15288173#15288173 – 2013-04-10 06:42:20

回答

2

嘗試

UIGraphicsBeginImageContextWithOptions(rect.size, NO, [[UIScreen mainScreen] scale]); 

更換

UIGraphicsBeginImageContext(rect.size); 

佔視網膜

+0

設置比例0的論據也適用於我想。 – Hgeg 2013-04-09 16:24:18

+0

,但它給我雙倍大小image.for例如(560,400)圖像。 – hacker 2013-04-10 06:10:23