Welcome!

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

Reply
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Icon in BBM profile box

I can't figure out how to add icons to BBM Profile Box Items.

First of all code:

	img_decode_callouts_t Callouts;
	img_lib_t ilib = NULL;
	img_t img;
	int rc = img_lib_attach(&ilib);
	if (rc != IMG_ERR_OK) {
		fprintf(stderr,"InitBBM(): img_lib_attach() failed returning %d\n", rc);
		return -1;
	}else{
		memset(&img, 0, sizeof(img));
    	memset(&Callouts, 0, sizeof(Callouts));
    	rc = img_load_file(ilib, "app/native/xxx.jpg", NULL, &img);
    	img_lib_detach(ilib);

    	if (rc == IMG_ERR_OK){
    		// Create BBM icon
    		bbmsp_result_t res;
    		res = bbmsp_image_create(&BBMAwardImage, BBMSP_IMAGE_TYPE_JPG, (const char*)img.access.direct.data, img.h*img.access.direct.stride);
    		if (res != BBMSP_SUCCESS){
    			fprintf(stderr, "InitBBM(): bbmsp_image_create() did not return BBMSP_SUCCESS\n");
    			return -1;
    		}
    		res = bbmsp_user_profile_box_register_icon(BBMAwardIconId, BBMAwardImage);
    		if (res != BBMSP_ASYNC){
    			fprintf(stderr, "InitBBM(): bbmsp_user_profile_box_register_icon() did not return BBMSP_ASYNC\n");
    			return -1;
    		}
    	}else{
    		fprintf(stderr, "InitBBM(): img_load_file() failed on loading BBM Award icon\n");
    		return -1;
    	}
    }

 Now let's see what documentation says about image format: "Images should be constructed by using the complete image file data that is read from the image source file, not just the canvas data. The image size must be > 0 and < * 32 KB (32 * 1024). Pixel size should be 333 x 333."

I tried to supply 333x333 jpeg and png images and bbmsp_image_create() failed with both of them.

Now puzzling math. GIMP by default creates png/jpeg images with 4 bytes per pixel, so 333 x 333 x 4 = 443,556 bytes for image with is more thatn 32x1024 bytes.
So I tried to gradually reduce image size and indeed looks like images size drops below 32x1024 bytes bbmsp_image_create() succeeds but that gives us about 90x90 image. Ok, let's see whether it works with this image size. So, bbmsp_image_create() succeeds, bbmsp_user_profile_box_register_icon() returns BBMSP_ASYNC but I don't think it succeeds (I don't receive message BBMSP_SP_EVENT_USER_PROFILE_BOX_ICON_ADDED).

Then when I add an item with bbmsp_user_profile_box_add_item() it is addedd successfully but there is no any icon - just empty space.

So, please clarify what type of image can be loaded here for icon, can't find it anywhere in documentation.

Thank you.

Please use plain text.
Administrator
MSohm
Posts: 14,525
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Icon in BBM profile box

The image requirements changed in the last release.  The resolution is now 119 x 119 with a 32KB max size.  PNG or JPG would be the recommended formats.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Icon in BBM profile box

Thanks for your reply but...

119*119= 14161 pixels which is (x4 bytes per pixel) = 56644 bytes. How does it fit into 32KB ?

Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Icon in BBM profile box

If you could send me an image that was successfully used by developers as an Icon in profile box I'd figure out needed format by myself...

Thanks.

Please use plain text.
Administrator
MSohm
Posts: 14,525
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Icon in BBM profile box

The images used in the bbmprofilebox sample application work:  https://github.com/blackberry/Cascades-Samples/tree/master/bbmprofilebox/assets/images 

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Icon in BBM profile box

I would be happy to test it but now with new release my app can't connect to BBM -\

Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Icon in BBM profile box

Ok, looking at Cascades sample I fixed my code -)))

This works:

    // Load Award's image
    FILE *fp = fopen("app/native/AwardIcon.png", "rb");
    if (!fp) {
    	fprintf(stderr, "InitBBM(): can not open icon image file, fopen() returned %d", errno);
        return -1;
    }
    // Get file size
    fseek(fp, 0, SEEK_END);
    int nFSize = ftell(fp);
    fseek(fp, 0, SEEK_SET);
    char *cFileRawData = (char*)malloc(nFSize);
    if (cFileRawData == NULL){
    	fprintf(stderr, "InitBBM(): can not allocate %d bytes of memory", nFSize);
    	fclose(fp);
    	return -1;
    }
    fread(cFileRawData, 1, nFSize, fp);
    fclose(fp);

    bbmsp_result_t res;
    res = bbmsp_image_create(&BBMAwardImage, BBMSP_IMAGE_TYPE_PNG, (const char*)cFileRawData, nFSize);
    if (res != BBMSP_SUCCESS){
    	fprintf(stderr, "InitBBM(): bbmsp_image_create() did not return BBMSP_SUCCESS\n");
        free(cFileRawData);
    	return -1;
    }
    res = bbmsp_user_profile_box_register_icon(BBMAwardIconId, BBMAwardImage);
    if (res != BBMSP_ASYNC && res != BBMSP_SUCCESS){
    	/* it is totally ok, if you have this BBMAwardIconId already loaded and used at least once*/
    	fprintf(stderr, "InitBBM(): bbmsp_user_profile_box_register_icon() did not return BBMSP_ASYNC but returned:%d\n", res);
        free(cFileRawData);
    	return -1;
    }
    free(cFileRawData);
    return 0;

 so no fancy load_image - just raw file! and I like it...

One think that bothers me a bit I can only register icon successfully once when I fist use this BBMAwardIconId=1 let's say. All consecutive app launches fail on bbmsp_user_profile_box_register_icon() although the icon can be successfully used in bbmsp_user_profile_box_add_item(). What's the logic here? Should I call some function to check first whether this IconId already registered?

Also from my observations image geometry does not matter what matters is file size, it must be less than 32K.

 

 

Please use plain text.
Administrator
MSohm
Posts: 14,525
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Icon in BBM profile box

You only need to register an icon once, but right now there isn't a way to query if the icon has been previously registered.  This is something we're planning to add in the future.  You can track the status of this feature here:

 

Create method to check if a ProfileBoxItem image is registered

 

If the image is a different size it will be scaled to fit.  So yes, you can use different resolutions but you could see scaling distortion if it's not 119 x 119.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Icon in BBM profile box

Voted for this feature request. Thanks!

Please use plain text.