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
Trusted Contributor
bbdev12345
Posts: 117
Registered: ‎09-06-2011
My Device: 9900
My Carrier: myself
Accepted Solution

post img to screen

I would really appreciate if anybody can offer a suggestion as to why I can't see an image on my screen which I have received over the network.

 

I know the child screen which I try to display my img on is visible because it has pan/zoom enabled and does pan/zoom so I know the screen is there but the image isn't.

 

My code is below..

 

	if (( rc = img_load(ilib, memory_stream, NULL, &img)) != IMG_ERR_OK) {
		fprintf(stderr, "img_load_file() failed: %d\n",  rc);
		//return -1;
	}


	if(rc != -1)
	{
		int Fsize[2];
		Fsize[0] = img.w;
		Fsize[1] = img.h;
		viewport_size[0] = img.w;
		viewport_size[1] = img.h;
		screen_set_window_property_iv(screen, SCREEN_PROPERTY_BUFFER_SIZE, Fsize);
		screen_create_window_buffers(screen, 1);
		screen_buffer_t bg_buf;
		screen_get_window_property_pv(screen, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)bg_buf);
		screen_get_buffer_property_pv(bg_buf, SCREEN_PROPERTY_POINTER, (void **)&img.access.direct.data);
		screen_get_buffer_property_iv(bg_buf, SCREEN_PROPERTY_STRIDE, (int *)&img.access.direct.stride);
		img.flags |= IMG_DIRECT;
		int rect[4] = { 0, 0, 1024, 600 };
		screen_post_window(screen, bg_buf, 1, rect, SCREEN_WAIT_IDLE );
	}

 

 

 

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

Re: post img to screen

based on which example you've created this code and expect it to work? just curious...

Please use plain text.
Trusted Contributor
bbdev12345
Posts: 117
Registered: ‎09-06-2011
My Device: 9900
My Carrier: myself

Re: post img to screen

I grabbed it (trying to work it out for myself) from this post http://supportforums.blackberry.com/t5/Native-Development/Reading-image-from-file-and-displaying-it/...

 

Is it completely wrong?

 

 

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

Re: post img to screen

Your source should be this https://github.com/blackberry/NDK-Samples/blob/master/Gesture/main.c

You can compile this sample and when it is working for you play with it as long as you wish.

Try to understand *how* it works regarding loading the image, especially if you are new to the platfom (or C programming in general).
Hint: by calling this 

screen_get_buffer_property_pv(screen_buf,SCREEN_PROPERTY_POINTER,(void**)&img->access.direct.data);

 you set up img's access.direct.data member to point to a "screen buffer" so whatever you fill it with will be visible on the screen. I.e. you have to first prepare your img by making this call, and then actually load image data from file/stream/whatever into this allocated space.

PS:

screen_get_window_property_pv(screen, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)bg_buf);

and

screen_get_window_property_pv(screen, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&bg_buf);

is a big difference ;-) 

Please use plain text.
Trusted Contributor
bbdev12345
Posts: 117
Registered: ‎09-06-2011
My Device: 9900
My Carrier: myself

Re: post img to screen

Changing the code around little so the img is setup first as you suggested has solved the problem, thank you for your help BGmot, you really have been my coding saviour today!

 

 

Please use plain text.