在iOS中绘制像素化图

时间:2014-02-27 14:31:18

标签: ios uikit core-graphics cgcontext cglayer

我正在绘制一个绘图应用程序,我正在绘制 CGlayers ,我正在以这种方式创建一个CGlayer

-(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 );
}

现在,当我的绘图Canvas可以动态增加/减少时,每当用户执行任何操作时,我再创建一个图层并将上一个图形存储到新的CGlayer 这样

-(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;
 }

一切正常,但是每当我绘制一些东西然后增加画布大小,再次绘制,然后增加画布大小,然后再画画等等时,会发生什么呢?

然后,我之前的绘图变得像素化,这是图像

enter image description here

0 个答案:

没有答案