问题
I am working on a drawing application, I am drawing into CGlayers, I am creating a CGlayer this way
-(void)drawRect
{
if(self.DrawingLayer == nil)
{
CGFloat scale = self.contentScaleFactor;
CGRect bounds = CGRectMake(0, 0, self.bounds.size.width * scale, self.bounds.size.height * scale);
CGLayerRef layer = CGLayerCreateWithContext(context, bounds.size, NULL);
CGContextRef layerContext = CGLayerGetContext(layer);
CGContextScaleCTM(layerContext, scale, scale);
self.DrawingLayer = layer;
}
CGContextDrawLayerInRect(context,rectSize, self.newDrawingLayer);
CGContextDrawLayerInRect(context, self.bounds, self.DrawingLayer );
}
Now as my drawing Canvas can be dynamically increased/decreased, whenever user performs any of the actions , I create one more layer and store the previous drawing on to the new CGlayer this way
-(void)canvasIncreased
{
rectSize = self.bounds
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat scale = self.contentScaleFactor;
CGRect bounds = CGRectMake(0, 0, self.bounds.size.width * scale, self.bounds.size.height * scale);
CGLayerRef layer = CGLayerCreateWithContext(context, bounds.size, NULL);
CGContextRef layerContext = CGLayerGetContext(layer);
CGContextScaleCTM(layerContext, scale, scale);
self.newDrawingLayer = layer;
CGContextDrawLayerInRect(layerContext, self.bounds, self.DrawingLayer);
self.DrawingLayer = nil;
}
Everything works fine, but what happens is that whenever I draw something then increase canvas size, the again draw, then increase canvas size, then again draw and so on,
then, my previous drawing is getting pixelated, here is the image
来源:https://stackoverflow.com/questions/22071515/drawing-getting-pixelated-in-ios