2014-01-06 33 views
0

感谢大家。我有解决方案在Java中将图像切割成不规则形状。但现在我想在iOS中实现这一点。如何使用物镜将图像切割成不规则形状c

这里是我的要求:

我用手指触摸来选择特定的部分并绘制图像,完成拉伸之后,我想绘制图像的一部分。我可以使用触摸来绘制,但我怎样才能剪切那个特定的部分?

我知道将图像切割成矩形和圆形,但不是特定的形状。

如果有人知道请帮帮我。

+0

:HTTPS://stackoverflow.com/questions/20943441/how-to-cut-an-image-into-irregular-shapes-using-objective-c –

回答

2

绘制一个封闭的CGPath并将其转换为图像蒙版。如果我有更多的经验,我会提供更多细节,但我只在天气应用程序中完成图表。指南应该有所帮助。

0

贝娄是具有选定矩形区域的公司图像的代码。但您可以用CGPath自定义您的选定区域,然后对图像进行编辑。

-(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]; 
} 
0
CGSize newSize = CGSizeMake(backGroundImageView.frame.size.width, backGroundImageView.frame.size.height); 
UIGraphicsBeginImageContext(newSize); 

[<Drawing Imageview> drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; 

[backGroundImageView.image drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeSourceIn alpha:1.0]; 

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 

UIGraphicsEndImageContext(); 
在我们这里这个链路解决方案
+0

这里绘图Imageview是你绘制的图像,你正在绘制不规则形状..这段代码适合我。我希望它可以帮助你。 –