Drawing getting pixelated in iOS

无人久伴 提交于 2019-12-13 05:08:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!