开发者

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

开发者 https://www.devze.com 2023-01-30 16:09 出处:网络
I\'m drawing an image with开发者_JS百科 strechable caps defined like the following: [bubbleImg stretchableImageWithLeftCapWidth:17 topCapHeight:12];

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

精彩评论

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

关注公众号