Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Posts: 14
Registered: ‎01-20-2013
My Device: Playbook
My Carrier: None

[Cocos2D-x] Can't use Playbook files (photos) to create CCSprites

We are having an issue, and we can't solve it.

We are developing a game and we want to read user photos and use them to make some backgrounds, we already set up the permissions, and we can read the "shared/photos" and "shared/camera" folders, but when we try to create the CCSprite, based on the file (all files are .jpg), the app crash. We tried the same method with Windows and it works.

So, what is the way to read and show images from Playbook tablet?


Some part of the code:

	CCLog("FILE=(%s) (col=%i,row=%i) (%i)",fpath,cont_col,cont_row,contImages);

	file	= fopen( fpath , "rb");
	if(file==NULL) { CCLog("no se pudo abrir archivo"); continue; }
	fseek (file , 0 , SEEK_END);
	lSize = ftell (file);
	// allocate memory to contain the whole file:
	buffer = (char*) malloc (sizeof(char)*lSize);
	if(buffer == NULL) { CCLog("buffer no alocado"); continue; }

	// copy the file into the buffer:
	result = fread(buffer,1,lSize,file);
	if (result != lSize) 
	{ CCLog("no leido todo"); continue; }
	char tex[32];
	CCLog("LEIDO : %c %c %c %c %c",tex[0],tex[1],tex[2],tex[3],tex[4]);
	// terminate
	fclose (file);
		// guarda path
		strcpy( pSprPath[contImages] , fpath );

		// Intenta crear un sprite con el archivo

		if(pImg[contImages] != NULL)
		{ CCLog("continue"); continue; }

		pImg[contImages]	= new CCImage();
		if(flagIsJpg == true)
			pImg[contImages]->initWithImageData( buffer , lSize , (cocos2d::CCImage::EImageFormat)0 , thumbsize, thumbsize );
			//pImg[contImages]->initWithImageFile( fpath ,  (cocos2d::CCImage::EImageFormat)0 );
		if(flagIsPng == true)
			pImg[contImages]->initWithImageData( buffer , lSize , (cocos2d::CCImage::EImageFormat)1 , thumbsize, thumbsize );
			//pImg[contImages]->initWithImageFile( fpath ,  (cocos2d::CCImage::EImageFormat)1 );

 Thanks a lot in advance