2009-12-17 107 views

回答

0

看一看this blog post,這對於iPhone OS 2.x的提供代碼& 3.0

+4

這篇文章doesen't幫助。這是關於根據iOS 4.x中修復的內置裁剪和縮放視圖中的默認方形矩形不能正確裁剪返回的圖像。我相信這個問題是關於改變預覽/裁剪功能的縱橫比的可能性。 Anybodu有幸運? – esbenr 2011-09-01 07:17:46

0

在委託方法的字典返回所有:

NSString *const UIImagePickerControllerMediaType; 
NSString *const UIImagePickerControllerOriginalImage; 
NSString *const UIImagePickerControllerEditedImage; 
NSString *const UIImagePickerControllerCropRect; 
NSString *const UIImagePickerControllerMediaURL; 
NSString *const UIImagePickerControllerReferenceURL; 
NSString *const UIImagePickerControllerMediaMetadata; 

我想,你已經使用EditedImage是非常沒用的...可能對於一些縮略圖...無論如何,info字典包含CropRect數據,唯一需要做的就是重新計算大小並自己裁剪OriginalImage,例如使用下面的代碼: UIImage: Resize, then Crop

我沒有測試過,這只是理論:) ...但在理論上,這應該工作:d

0

從圖像拾取獲得的圖像,並給作物的功能不同模塊後。所以用戶可以選擇他們想要剪裁的圖像部分。

+0

這應該是一條評論。沒有答案。 – Praveenkumar 2012-10-05 10:37:38

3

我做了一個類似的項目。你必須使用圖像控制器。在圖像控制器上方,您必須添加另一個圖像控制器(因爲這是您的裁剪區域) aboveImageController的未填充/空白部分是您將採用的位置。 (所以你應該有一個形象與小320x480大小和320x385空在其中。)

UIImage *image=theimageView.image; 
CGSize newSize; 
newSize.width=320; 
newSize.height=385; 
UIGraphicsBeginImageContext(newSize); 

//x=0 (because widhth : 320) y=0 (aboveImageController's empty part's start) 
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; 
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

CGImageRef imageRef = CGImageCreateWithImageInRect([newImage CGImage], rect); 
UIImage *img = [UIImage imageWithCGImage:imageRef]; 
CGImageRelease(imageRef); 
0

您可以使用此

UIImage *image1 = [self resizeImage:image width:320 height:385]; 


-(UIImage *)resizeImage:(UIImage *)image width:(int)wdth height:(int)hght{ 
    int w = image.size.width; 
    int h = image.size.height; 
    CGImageRef imageRef = [image CGImage]; 
    int width, height; 
    int destWidth = wdth; 
    int destHeight = hght; 
    if(w > h){ 
     width = destWidth; 
     height = h*destWidth/w; 
    } 
    else { 
     height = destHeight; 
     width = w*destHeight/h; 
    } 
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
    CGContextRef bitmap; 
    bitmap = CGBitmapContextCreate(NULL, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedFirst); 

    if (image.imageOrientation == UIImageOrientationLeft) { 

     CGContextRotateCTM (bitmap, M_PI/2); 
     CGContextTranslateCTM (bitmap, 0, -height); 

    } else if (image.imageOrientation == UIImageOrientationRight) { 

     CGContextRotateCTM (bitmap, -M_PI/2); 
     CGContextTranslateCTM (bitmap, -width, 0); 

    } 
    else if (image.imageOrientation == UIImageOrientationUp) { 

    } else if (image.imageOrientation == UIImageOrientationDown) { 

     CGContextTranslateCTM (bitmap, width,height); 
     CGContextRotateCTM (bitmap, -M_PI); 
    } 

    CGContextDrawImage(bitmap, CGRectMake(0, 0, width, height), imageRef); 
    CGImageRef ref = CGBitmapContextCreateImage(bitmap); 
    UIImage *result = [UIImage imageWithCGImage:ref]; 
    CGContextRelease(bitmap); 
    CGImageRelease(ref); 

    return result; 

} 
2

退房GKImagePicker

https://github.com/gekitz/GKImagePicker

示例項目只有iphone和只支持相冊,但我很容易擴展到包括ipad和相機。我用它來做一個自定義裁剪視圖,它是任何尺寸大小的圓角矩形。

+0

在使用GKImagePicker時,您是如何擺脫原始Apple重拍/使用屏幕的?現在,如果我用相機拍攝照片,首先會顯示該屏幕,如果按'使用',那麼該屏幕的GKImagePicker裁剪版本會立即顯示。我只想要GKImagePicker屏幕。 – Ramsel 2013-09-23 21:46:40

+0

@RobertWagstaff,你是如何得到GKImagePicker使用相機的?你仍然可以用相同的方法設置作物長度,或者你只是在原始代碼沒有的情況下實現自己的相機方法嗎? – DelightedD0D 2014-05-17 09:49:14

+0

@ DelightedD0D是的,我實現了我自己的相機方法 – 2014-05-21 18:35:25