Mansi Panchal
Mansi Panchal

Reputation: 2357

Images are not displayed and showing error like "cocos2d: CCTexture2D: Using RGB565 texture since image has no alpha"

I am making an application using Box2D in which i am getting images from Asset Library and displaying them as sprites.

here is the code which i have done :

Getting Images from asset library :

CGImageRef imgRef = [[mutArrAssetPhotos objectAtIndex:i] thumbnail];

Creating Texture2D :

CCTexture2D *spriteTexture = [[CCTexture2D alloc]initWithCGImage:imgRef resolutionType:kCCResolutionUnknown];

Creating sprites from textures :

CCSprite *paddle = [CCSprite spriteWithTexture:spriteTexture];

This gives me warning in console like :

"cocos2d: CCTexture2D: Using RGB565 texture since image has no alpha"

Still in simulator it works fine though warning but in device images are not being displayed.

But instead if i used :

CCSprite *paddle = [CCSprite spriteWithFile:@"img.png"];

it is working fine and is not giving any warning also.

Can anyone help please ?? Thanks in Advance.

Upvotes: 5

Views: 1414

Answers (2)

Mansi Panchal
Mansi Panchal

Reputation: 2357

I've solved it. Somehow i managed to recreate the image, from which i was creating sprite.

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]];

And for updating the image, i redraw it so that i do not get any alpha warnings.The update method is like this :

-(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;
}

Upvotes: 3

giorashc
giorashc

Reputation: 13713

I think (could not find docs to confirm tough) that the thumbnail changes the image format so you get a plain no alpha image ref.

Try using the following for creating the right image ref :

CGImageRef imgRef = [[[mutArrAssetPhotos objectAtIndex:i] defaultRepresentation] fullResolutionImage];

Upvotes: 0

Related Questions