Breaking News
Home / iOS / iOS Snippets / How to load image from PhotoGallery into a CCSprite?

How to load image from PhotoGallery into a CCSprite?

Sinppet

The Asset Library is used here, so add import.

#import “AssetsLibrary/AssetsLibrary.h”

 

  CCSprite *playPhoto;

  CCLOG(@”Photo %@”,dataManager.playerPhoto);

// check if the URL is an asset URL from the Photo Gallery.

    if(dataManager.playerPhoto != nil && [dataManager.playerPhoto rangeOfString:@”asset”].location !=NSNotFound)
    {
       
        NSURL *referenceURL = [[NSURL alloc] initWithString:dataManager.playerPhoto];
       
        ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
        [library assetForURL:referenceURL resultBlock:^(ALAsset *asset) {
            // code to handle the asset here

           
            // Let’s create a sprite now that we have an image
            CCSprite *imagecc = [CCSprite spriteWithCGImage:[UIImage imageWithCGImage:[asset thumbnail]].CGImage key:@”playerPhoto”];
            [playerPhoto setTexture: imagecc.texture];

        } failureBlock:^(NSError *error) {
            // error handling
        }];
        [library release];
    }

 

[pb_builder]

Check Also

EKCalendar – That account does not allow calendars to be added or removed

Usecase When I am trying to create a new Calendar programmatically using the EventKit API …

Advertisment ad adsense adlogger