视网膜中的ClipToMask

Cus*_*ons 1 iphone xcode ios ios5

对于iPhone,我使用CGContextClipToMask剪切图像.

在320x480,它看起来很漂亮.但是在视网膜显示器/模拟器中,屏蔽看起来像是在320x480中完成,然后扩展到640x960 - 它看起来有点邋..

正在使用正确的640x960图像(我已标记它们以确保).

我的代码如下.有谁知道它可能是什么?非常感谢一些帮助.非常感谢.

-(id)makeMainImage:(UIImage*)initMaskImg initMainImage:(UIImage*)initMainImage{

    //get images
    UIImage *mainImg = initMainImage;
    UIImage *maskImg = initMaskImg;

    //new context, to draw image into
    UIGraphicsBeginImageContext(mainImg.size);
    CGContextRef context = UIGraphicsGetCurrentContext();

    //position context
    CGContextTranslateCTM(context, 0,480);
    CGContextScaleCTM(context, 1.0, -1.0);//flip coordinates

    //rect
    CGRect imageRect = CGRectMake(0, 0, 320, 480);

    //set mask
    CGContextClipToMask(context, imageRect, maskImg.CGImage);

    //main image
    CGContextDrawImage(context, imageRect, mainImg.CGImage);

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();    

    return newImage;
}
Run Code Online (Sandbox Code Playgroud)

Dav*_*d H 5

不要使用'UIGraphicsBeginImageContext',请使用

UIGraphicsBeginImageContextWithOptions(size, opaque, 0); // last option is the scale option
Run Code Online (Sandbox Code Playgroud)

这就是你创建视网膜图像的方法.