开发者

adding a picture to the middle of a drawn rectangle [iPhone]

开发者 https://www.devze.com 2023-01-29 00:40 出处:网络
I have the following code that I a开发者_C百科m using to draw a simple rectangle inside the middle of a drawn circle, however I would like to be able to replace this rectangle with an UIImage, does an

I have the following code that I a开发者_C百科m using to draw a simple rectangle inside the middle of a drawn circle, however I would like to be able to replace this rectangle with an UIImage, does anyone know how this can be done?

CGContextSetRGBStrokeColor(context, 255.0/255.0, 255.0/255.0, 255.0/255.0, 1.0);
CGMutablePathRef path = [self newPathForRect:CGRectMake(center.x - kRoundedRectRadius, center.y - kRoundedRectRadius, kRoundedRectRadius * 2.0, kRoundedRectRadius * 2.0)];
CGContextAddPath(context, path);
CGContextDrawPath(context, kCGPathStroke);
CGPathRelease(path);


You'll no longer be able to use a CGPathRef to do it, but the CGContextDrawImage() function will do what you want. Just pass in the result of -[UIImage CGImage]:

rect = CGRectMake(
    center.x - kRoundedRectRadius,
    center.y - kRoundedRectRadius,
    kRoundedRectRadius * 2.0,
    kRoundedRectRadius * 2.0
);

CGContextDrawImage(context, rect, myImage.CGImage);
0

精彩评论

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