【问题标题】:UIImage stretchableImageWithLeftCapWidth doesn't work when drawing to a quartz contextUIImage stretchableImageWithLeftCapWidth 在绘制到石英上下文时不起作用
【发布时间】:2010-12-16 04:55:12
【问题描述】:

我正在绘制一个具有如下定义的可拉伸大写的图像:

[bubbleImg stretchableImageWithLeftCapWidth:17 topCapHeight:12];

这在 UIImageView 内工作正常,但在绘制如下图像时不起作用:

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

.. 我有点怀疑它行不通。绘制到 CG 上下文时是否有可拉伸的帽子图像的解决方案?

【问题讨论】:

    标签: iphone uiimage quartz-graphics cgcontext


    【解决方案1】:

    绘制可拉伸图像时,不要使用 CGImage 属性,因为它返回底层未拉伸位图。而是直接使用 UIImage 的绘制方法。

    如果您在不寻常的上下文中绘图(在纯 Core Graphics 上下文中的 UIView/CALayer 绘图方法之外),您可能需要将 UIKit 绘图包装在 UIGraphicsPushContext()/UIGraphicsPopContext() 调用中。

    【讨论】:

    • 不错。我使用了 drawAtRect 方法。仍然遇到一些奇怪的渲染问题.. 水平线 - 等等
    猜你喜欢
    • 1970-01-01
    • 2014-04-09
    • 2016-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多