2

トリミングに使用される長方形

この四角形を使用して画像をトリミングしようとしていますが、四角形を引き伸ばす方法がわかりませUIViewblack border。DO を伸ばすと、両方UIViewのフレームを変更する必要がありますか??

Pinchgesture長方形または他の方法を伸ばすために使用する必要がありますか??

ここでは、4 つの青いハンドラーがUIViews です。それらのドラッグをどのように決定しますか?? あれば提案してください。

4

1 に答える 1

2

ボックスを選択して画像をトリミングするための次のコード。

-(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];
}

これが多くのことに役立つことを願っています

于 2012-08-17T10:58:27.140 に答える