代码之家  ›  专栏  ›  技术社区  ›  Jorge

CGIMAGEREF和绘图层

  •  0
  • Jorge  · 技术社区  · 16 年前

    我有这个代码:

    CGDataProviderRef provider = CGDataProviderCreateWithFilename([myFile UTF8String]);
    CGImageRef img = CGImageCreateWithJPEGDataProvider(provider, NULL, true, kCGRenderingIntentDefault);
    

    稍后,我以如下方式将cgimageref加载到uiimage中:

    UIImage *uiImage = [[UIImage alloc] initWithCGImage:destImage];
    

    我想在那个图像上画一个圆圈。该点是圆的移动,因此必须删除并重新绘制。我想实现这一点的最佳方法是使用层,所以我的问题是:如何向代码中添加层并在其上绘制圆?以后如何重置图层并重新绘制该圆?

    谢谢您!

    1 回复  |  直到 16 年前
        1
  •  0
  •   Ben Gottlieb    16 年前

    您需要使用uiImageView,然后向该视图添加单独的层。如果层[圆]移动,只需将其位置属性设置为新的中心;视图系统将负责重新组合所有内容。

    若要使圆显示在层中,可以使用固定图像、子类Calayer和重写DrawInContext:,或者设置委托并实现DrawLayer:InContext:。