Opengl es 图像不显示,显示错误,如;cocos2d:CCTexture2D:使用RGB565纹理,因为图像没有alpha“;

Opengl es 图像不显示,显示错误,如;cocos2d:CCTexture2D:使用RGB565纹理,因为图像没有alpha“;,opengl-es,cocos2d-iphone,box2d-iphone,ccsprite,texture2d,Opengl Es,Cocos2d Iphone,Box2d Iphone,Ccsprite,Texture2d,我正在使用Box2D制作一个应用程序,从资源库中获取图像,并将其显示为精灵 以下是我所做的代码: 从资产库获取图像: CGImageRef imgRef = [[mutArrAssetPhotos objectAtIndex:i] thumbnail]; CCTexture2D *spriteTexture = [[CCTexture2D alloc]initWithCGImage:imgRef resolutionType:kCCResolutionUnknown]; 创建纹理2d: CG

我正在使用Box2D制作一个应用程序,从资源库中获取图像,并将其显示为精灵

以下是我所做的代码:

从资产库获取图像:

CGImageRef imgRef = [[mutArrAssetPhotos objectAtIndex:i] thumbnail];
CCTexture2D *spriteTexture = [[CCTexture2D alloc]initWithCGImage:imgRef resolutionType:kCCResolutionUnknown];
创建纹理2d:

CGImageRef imgRef = [[mutArrAssetPhotos objectAtIndex:i] thumbnail];
CCTexture2D *spriteTexture = [[CCTexture2D alloc]initWithCGImage:imgRef resolutionType:kCCResolutionUnknown];
从纹理创建精灵:

CCSprite *paddle = [CCSprite spriteWithTexture:spriteTexture];
这在控制台中为我提供了警告,如:

"cocos2d: CCTexture2D: Using RGB565 texture since image has no alpha"
仍然在模拟器中,虽然发出警告,但工作正常,但设备中的图像未显示

但如果我使用:

CCSprite *paddle = [CCSprite spriteWithFile:@"img.png"];
它工作正常,也没有发出任何警告

有人能帮忙吗??提前感谢。

我想(找不到文档来确认)缩略图改变了图像格式,因此您可以得到一个普通的无alpha图像参考

尝试使用以下方法创建正确的图像引用:

CGImageRef imgRef = [[[mutArrAssetPhotos objectAtIndex:i] defaultRepresentation] fullResolutionImage];
我已经解决了。 不知怎的,我成功地重新创建了这个图像,从中我创建了精灵

CGImageRef imgRef = [[mutArrAssetPhotos objectAtIndex:i] thumbnail];
        UIImage *image = [self updateImage:[UIImage imageWithCGImage:imgRef]];
        imgRef = image.CGImage;

        CCSprite *paddle = [CCSprite spriteWithCGImage:image.CGImage key:[NSString stringWithFormat:@"%d",i]];
为了更新图像,我重新绘制了它,这样我就不会得到任何alpha警告。更新方法如下:

-(UIImage *) updateImage:(UIImage *)image
{
    UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
    imgView.frame = CGRectMake(0,50, image.size.width,image.size.height);

    image = [self captureImageFrom:imgView];

    [imgView release];
    return image;
}

-(UIImage *) captureImageFrom:(UIImageView *)view{

    UIGraphicsBeginImageContext(view.frame.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:context];
    UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return screenShot;
}

但我只需要缩略图像,因为我一次要显示很多图像,但我不能以全分辨率显示它们。但它能工作吗?你知道bits格式的错误吗?如果不只是将精灵缩放到你想要的大小。不,我尝试了全分辨率图像。但它不起作用。即使缩放,它也会显示相同的警告,因为图像没有alpha。这可能是您的CCTexture2D造成的问题。(顺便说一句,我不熟悉这个纹理初始化签名)。尝试直接使用CCSpriteTried的spriteWithCGImage类方法使用imgRef对象创建精灵。。但仍然没有成功。主要问题是,在模拟器中,图像显示和工作正常。但在iphone中,它根本没有显示出来(我不认为“cocos2d:CCTexture2D:UsingRGB565Texture,因为图像没有alpha”真的是一个警告,只是一个通知。它没有找到任何alpha值,而是选择了另一种更快速绘制的颜色格式。您可以用这种颜色格式创建图像,在保存之前关闭alpha。