2011-11-24 136 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