2011-11-24 124 views
3

我要尋找一個很好的教程或示例代碼,這將展示如何裁剪圖像從iPhone相機拍攝使用選定區域的矩形框來裁剪圖像?

東西的

enter image description here

行,但你將控制角落你手指

任何提示將大大appericated,因爲我嘗試了許多方式,但沒有得到一個結果。

+0

同樣的問題,誰不回答http://stackoverflow.com/questions/2754618/how-to-crop-an-image-using-rectangale-overlay -and-touch-on-iphone – Marios

+0

你試過了什麼?你試過什麼錯? –

+0

http://stackoverflow.com/questions/8238464/croping-an-uiimage-using-frame-to-cut我試着看這個鏈接 – Marios

回答

7

的按鈕操作的一些變化

-(IBAction) cropImage:(id) sender{ 


     // Create rectangle that represents a cropped image 
     // from the middle of the existing image 

    float xCo,yCo; 

    float width=bottomCornerPoint.x-topCornerPoint.x; 

    float height=bottomCornerPoint.y-topCornerPoint.y; 


    if(width<0) 

    width=-width; 


    if(height<0) 

     height=-height; 


    if(topCornerPoint.x <bottomCornerPoint.x) 

    { 

    xCo=topCornerPoint.x; 

    } 

    else 
    { 
      xCo=bottomCornerPoint.x; 
     } 


     if(topCornerPoint.y <bottomCornerPoint.y) 

    { 

      yCo=topCornerPoint.y; 

     } 


    else { 

      yCo=bottomCornerPoint.y; 

     } 


     CGRect rect = CGRectMake(xCo,yCo,width,height); 

     // Create bitmap image from original image data, 
     // using rectangle to specify desired crop area 

     UIImage *image = [UIImage imageNamed:@"abc.png"]; 


     CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect); 

     UIImage *img = [UIImage imageWithCGImage:imageRef]; 

     CGImageRelease(imageRef); 


     // Create and show the new image from bitmap data 

     imageView = [[UIImageView alloc] initWithImage:img]; 

     [imageView setFrame:CGRectMake(110, 600, width, height)]; 

     imageView.image=img; 

     [[self view] addSubview:imageView]; 

     [imageView release]; 



    } 
+1

@ceacare那麼爲什麼你將它標記爲正確答案? – phi

+0

@ceacare它工作正常。我在這裏粘貼之前已經過測試。而且每個人都可以在這裏幫助,而不是根據你的要求爲你完成整個項目。 –

+0

好吧好吧我可以理解阿尼爾,我只是這個發展的新手 – Marios