开发者

Draw image in triangle region iphone

I draw an triangle using these piece of code

CGPoint center;

center = CGPointMake(x1, x2);
CGContextMoveToPoint(context, center.x, center.y);
for(int i = 0; i < 3; i++)
{
    switch (i) {
        case 0:
            CGContextAddLineToPoint(context, y1, y2);
            break;
        case 1:
            CGContextAddLineToPoint(context, z1, z2);
            break;
  开发者_JAVA技巧      case 2:
            CGContextAddLineToPoint(context, x1, x2);
            break;
        default:
            break;
    }

}

Now the triangle has drawn in my uiview.I have an image size should be (420*300).I want to load this image in the triangle region . (Not out of this triangle region).

Can anyone help me ?

Thanks in advance.....


After adding the lines into the context call CGContextClip then draw your image (CGContextDrawImage). Your image will be clipped by the path. You can then use the same path to draw the triangle as lines too, if you like.

You'll probably find that your image is upside down, so you may need to apply a transform before drawing it - something like:

CGContextTranslateCTM( context, 0, image.size.height );

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜