图像出现像素化

时间:2012-06-29 18:55:02

标签: objective-c ios

这就是我想要做的事情

  1. 创建UIImage视图。
  2. 做一些绘画
  3. 按分享按钮与图像共享图像。
  4. 我的代码在iPad和iPhone上运行完美。视网膜显示出现问题。所以我的猜测是某种规模没有得到正确处理,但不确定我做错了什么。这是我的代码

    // Create the UIImageView named centerCanvas
    // Do the drawing
    CGPoint origin = centerCanvas.frame.origin;
    CGSize  size   = centerCanvas.frame.size;
    CGSize screenSize = [self returnScreenSize];
    CGRect  rect   = CGRectMake(origin.x, origin.y, size.width, size.height);
    UIGraphicsBeginImageContext(screenSize);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self.view.layer renderInContext:context];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], rect);
    [shareView setImage:[UIImage imageWithCGImage:imageRef]]; 
    
    
    -(CGSize) returnScreenSize
    {
        CGRect screenBounds = [[UIScreen mainScreen] bounds];
        CGFloat screenScale = [[UIScreen mainScreen] scale];
        CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale,screenBounds.size.height * screenScale);
        return screenSize;
    }
    

1 个答案:

答案 0 :(得分:1)

尝试使用

    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);

而不是旧的UIGraphicsBeginImageContext,它使用等于1的比例因子(上面的第三个参数)。通过将0.0作为比例因子,您可以获得当前屏幕的比例因子。看看reference