1

カメラで写真を撮るiPhoneアプリに取り組んでいます。今後は、画像をさまざまな形 (最も重要な三角形) にスライスできるはずです。誰かが私に正しい方向や例などのポイントを教えてくれますか?私は三角形ではなく正方形にスライスすることを可能にしました.

(更新) 正方形のスライスを作成するために、次のコード スニペットを使用しました

CGRect ClippedRect= CGRectMake(0, 150, 320.0, 230.0);//example numbers
CGImageRef imageRef = CGImageCreateWithImageInRect([OriginalUIImage CGImage], ClippedRect);
UIImage *resultUIImage=[[UIImage alloc]initWithCGImage:imageRef];

すべての助けに感謝します

よろしく

解決済み:

uiimage をマスキングする方法を使用しました。したがって、戦略は次のとおりです。 1. カメラとスケールから写真を撮ります。2. ユーザーに uiimageview で図を描画させ、それを黒色で塗りつぶし、これから UIImage を作成します。3. ユーザーが生成した画像でカメラからの画像をマスクします。画像をマスキングするには、 http://www.developers-life.com/resize-and-mask-an-image.htmlの次の方法を使用します

- (UIImage*) maskImage:(UIImage *)image  {

 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

 UIImage *maskImage = [UIImage imageNamed:@"mask.png"];
 CGImageRef maskImageRef = [maskImage CGImage];

 // create a bitmap graphics context the size of the image
 CGContextRef mainViewContentContext = CGBitmapContextCreate (NULL, maskImage.size.width, maskImage.size.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);


 if (mainViewContentContext==NULL)
      return NULL;

 CGFloat ratio = 0;

 ratio = maskImage.size.width/ image.size.width;

 if(ratio * image.size.height < maskImage.size.height) {
      ratio = maskImage.size.height/ image.size.height;
 } 

 CGRect rect1  = {{0, 0}, {maskImage.size.width, maskImage.size.height}};
 CGRect rect2  = {{-((image.size.width*ratio)-maskImage.size.width)/2 , -((image.size.height*ratio)-maskImage.size.height)/2}, {image.size.width*ratio, image.size.height*ratio}};


 CGContextClipToMask(mainViewContentContext, rect1, maskImageRef);
 CGContextDrawImage(mainViewContentContext, rect2, image.CGImage);


 // Create CGImageRef of the main view bitmap content, and then
 // release that bitmap context
 CGImageRef newImage = CGBitmapContextCreateImage(mainViewContentContext);
 CGContextRelease(mainViewContentContext);

 UIImage *theImage = [UIImage imageWithCGImage:newImage];

 CGImageRelease(newImage);

 // return the image
 return theImage;

}

助けてくれてありがとう

4

2 に答える 2

1

次のようなものを試してください:
http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html
この説明が正しければ、マスクとして黒い画像を作成し、それを画像に適用するだけです。

于 2011-03-21T15:11:37.620 に答える
0

このアプローチを使用できるはずです: UIGraphicsBeginImageContextWithOptionsを使用して新しい画像を作成し(同等の CoreGraphics を使用することもできますが、より多くの作業が必要です)、必要な形状のベジェ パスを作成し、[yourBezierPath addClip]を呼び出してから、その文脈でのイメージ。その後、 UIGraphicsGetImageFromCurrentImageContextを使用して結果の画像を取得できます。後は必ず電話してくださいUIGraphicsEndImageContext()。で画像を作成するには、この質問を参照してくださいUIGraphicsBeginImageContextWithOptions

于 2011-03-21T15:18:30.067 に答える