0

我正在使用 CgLayers 在 iOS 中绘图,现在我想存储这些图层并稍后检索它,所以我想知道有哪些可用选项。我尝试使用 NSMutableDictionary,下面是代码,

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{   
    CGLayerRef testLayer = CGLayerCreateWithContext(UIGraphicsGetCurrentContext(),   self.bounds.size, NULL);

    CGContextRef context = CGLayerGetContext(testLayer);

    CGContextDrawLayerAtPoint(context, CGPointZero, myLayerRef); 

// here myLayerRef is my original layer


    NSValue *layerCopy = [NSValue valueWithPointer:testLayer];

    NSDictionary *lineInfo = [NSDictionary dictionaryWithObjectsAndKeys:layerCopy, @"IMAGE",
                              nil]; 

    [m_pathArray addObject:lineInfo];    

}

-(void) retrieve
{
    NSDictionary *lineInfo = [m_pathArray lastObject];


    NSValue *val = [lineInfo valueForKey:@"IMAGE"];

    CGLayerRef layerRef = (CGLayerRef) [val pointerValue];


    CGContextRef context1 = CGLayerGetContext(layerRef);
    CGContextDrawLayerAtPoint(context1, CGPointMake(00, 00),layerRef);
    [self setNeedsDisplayInRect:self.bounds];   
}

问候兰吉特

4

0 回答 0