开发者

UIImage stretchableImageWithLeftCapWidth doesn't work when drawing to a quartz context

I'm drawing an image with开发者_JS百科 strechable caps defined like the following:

[bubbleImg stretchableImageWithLeftCapWidth:17 topCapHeight:12];

And that was working fine when inside a UIImageView but it doesn't work when drawing the image like the following:

CGContextDrawImage(context, CGRectMake(x, y, width, height), image.CGImage);

.. which I kind of suspected it wouldn't work. Is there a solution for stretchable cap images when drawing to a CG context?


When drawing a stretchable image, don't use the CGImage property, because it returns the underlying unstretched bitmap. Instead use UIImage's drawing methods directly.

If you are drawing in an unusual context (outside of UIView/CALayer drawing methods in a pure Core Graphics context), you may need to wrap UIKit drawing in UIGraphicsPushContext()/UIGraphicsPopContext() calls.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜