Images are not displayed and errors such as "cocos2d: CCTexture2D: use RGB565 texture because the image does not have alpha" are displayed

I am building an application using Box2D in which I get images from the asset library and display them as sprites.

here is the code i made:

Retrieving Images from the Resource 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 a warning in the console, for example:

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

It still works fine in the simulator, although it’s a warning, but the device’s images are not displayed.

But instead, if I used:

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

It works fine and gives no warning either.

Can anyone help? Thanks at Advance.

+5
2

. - , .

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

, -. :

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

( ), , - ref.

ref:

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

All Articles