【问题标题】:How can I draw an CGImageRef context on the screen?如何在屏幕上绘制 CGImageRef 上下文?
【发布时间】:2010-10-26 15:00:38
【问题描述】:

我有一个漂亮的 CGImageRef 上下文,我创建了一整天来获取 alpha 值;)

它是这样定义的:

CGContextRef context = CGBitmapContextCreate (bitmapData, pixWidth, pixHeiht 8, pixWidth, NULL, kCGImageAlphaOnly);

因此,就我的理解而言,该上下文以某种方式代表了我的形象。但是“实际上”,在内存中的某处不可见。

我可以将其填充到 UIImageView 中或直接将其绘制到屏幕上吗?我猜 alpha 会被转换为灰度或类似的东西。

【问题讨论】:

    标签: iphone uikit core-graphics


    【解决方案1】:

    您可以通过调用创建UIImage

    + (UIImage *)imageWithCGImage:(CGImageRef)cgImage

    然后使用以下方法绘制UIImage

    - (void)drawAtPoint:(CGPoint)point

    【讨论】:

      【解决方案2】:

      去看看CGBitmapContextCreateImage(),它可以从你的位图上下文中给你一个CGImageRef。然后,您可以使用 CGContext... 函数绘制它或使用 +[UIImage imageWithCGImage:] 制作 UIImage。

      【讨论】:

        【解决方案3】:
        CGSize size = ...;
        UIGraphicsBeginImageContext(size);
        ...
        UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        ...
        CGPoint pt = ...;
        [img drawAtPoint:pt];
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-06-15
          • 1970-01-01
          • 2017-10-22
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多