2010-12-04 21 views
0

我用下面的代碼在繪製的圓的中間繪製一個簡單的矩形,但是我希望能夠用這個矩形替換這個矩形一個UIImage,有沒有人知道如何做到這一點?添加圖片到繪製矩形的中間[iPhone]

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); 

回答

0

您將不再能夠使用CGPathRef做到這一點,但CGContextDrawImage()功能會做你想要什麼。只是通過在-[UIImage CGImage]結果:

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

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

可以請您提供一些代碼來幫助我,因爲即時通訊困惑如何將contextDrawImage的路徑添加到我想將它添加到 – 2010-12-04 10:23:48