【发布时间】:2013-03-16 20:33:46
【问题描述】:
我有一个UIImage,在缩放之前我知道它没问题。
我需要对其进行缩放,以便将其设置为 ccsprite 。
我缩放它,但后来我得到了一个白色的图像..
UIImage *scaled=[newImage copy];
//scale the image
CGRect screenRect = CGRectMake(0, 0, 640.0, 960.0);
UIGraphicsBeginImageContext(screenRect.size);
scaled = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CCSprite * image = [CCSprite spriteWithCGImage:scaled.CGImage
key:[NSString stringWithFormat:@"%d",[localImagesSpritesArray count]]];
会是什么?
【问题讨论】:
-
您在哪里绘制要缩放到新上下文中的图像? 提示:
CGContextDrawImage(context, screenRect, scale.CGImage); -
为什么要复制
newImage然后把结果扔掉? -
另外,您不应该对
screenRect进行硬编码。你应该从 UIScreen 获得它。您可能还想使用UIGraphicsBeginImageContextWithOptions而不是UIGraphicsBeginImageContext;WithOptions版本允许您指定上下文的比例因子,或要求它自动检测。您正在使用的函数无条件使用1.0的比例因子,它适用于非 Retina 图像。
标签: ios objective-c uiimage core-graphics