iphone - 视网膜中的ClipToMask

标签 iphone ios xcode 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;
}

最佳答案

不要使用'UIGraphicsBeginImageContext',请使用

UIGraphicsBeginImageContextWithOptions(size, opaque, 0); // last option is the scale option

这是创建视网膜图像的方式。

关于iphone - 视网膜中的ClipToMask,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12308206/

相关文章:

iphone - 类似卡片堆栈的控件来显示屏幕

iphone - 发出来自其他设备的符号化崩溃日志

ios - 本地通知的自定义声音不起作用

iphone - 从 map 坐标获取 CGPoint 或从 MKMapPoint iphone 获取 CGPoint

iphone - 将网站保存到 iPhone 上的主屏幕 - 强制名称

objective-c - 删除 UITableView 中的行时出错

ios - 如何制作可重用的 UIView

iphone - 试图显示 map 方向跟踪而不是谷歌地图中的方向列表(Xcode)

ios - 打开 Storyboard时 xcode 9 崩溃

objective-c - iOS截图部分画面