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
Highlighted
Super Contributor
Posts: 306
Registered: ‎08-10-2010
My Device: Not Specified

Re: Adivice on libimg use.

Hi dr_prog.

 

I am successfully load the jpg image using the Libimg library. I use the code which is given in the touch gesture sample application provided by the blackberry.  I modify the Gesture application and only use the load image part of code from that application.

 

If this anwser helpful or resolve your issue like my post.

Developer
Posts: 1,636
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: Adivice on libimg use.


smcveigh wrote:

As others have alluded to, there are a few ways you might consider rendering data to the screen.

  1. render directly to the window buffer
  2. create a pixmap, create a pixmap buffer, render data to the pixmap buffer, then blit that to the window buffer
  3. allocate some memory, render your data there, create a pixmap, attach your memory pointer as the pixmap buffer, then blit that pixmap to the window buffer.

 

In your code, it seems you were heading down path #2, but you were allocating imgBuffer yourself, which does not make sense in that case.

 

Here's an example I just threw together which takes approach #2.

 

	screen_context_t ctx;
	screen_window_t window;
	screen_buffer_t winbuf;
	screen_pixmap_t pixmap;
	screen_buffer_t pixbuf;
	int pixsize[2] = { 200, 200 };  // create a pixmap @ 200x200
	int winsize[2] = { 600, 600 };  // create a window @ 600x600
	int rect[4] = { 0, 0, 600, 600 }; // bounding box for the full window
	int fmt = SCREEN_FORMAT_RGBA8888;
	int usage = SCREEN_USAGE_READ | SCREEN_USAGE_WRITE;
	unsigned long *dataptr;
	int i;
	screen_create_context(&ctx, SCREEN_APPLICATION_CONTEXT);
	screen_create_window_type(&window, ctx, SCREEN_APPLICATION_WINDOW);
	screen_set_window_property_iv(window, SCREEN_PROPERTY_FORMAT, &fmt);
	screen_set_window_property_iv(window, SCREEN_PROPERTY_BUFFER_SIZE, winsize);
	screen_create_window_buffers(window, 1);
	screen_get_window_property_pv(window, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)&winbuf);
	sleep(1);
	screen_create_pixmap(&pixmap, ctx);
	screen_set_pixmap_property_iv(pixmap, SCREEN_PROPERTY_USAGE, &usage);
	screen_set_pixmap_property_iv(pixmap, SCREEN_PROPERTY_FORMAT, &fmt);
	screen_set_pixmap_property_iv(pixmap, SCREEN_PROPERTY_BUFFER_SIZE, pixsize);
	screen_create_pixmap_buffer(pixmap);
	screen_get_pixmap_property_pv(pixmap, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)&pixbuf);
	screen_get_buffer_property_pv(pixbuf, SCREEN_PROPERTY_POINTER, (void**)&dataptr);
	for (i=0; i < pixsize[0] * pixsize[1]; i++) {
		// fill with some sort of pattern.
		// in the imglib example, you would load your img into the memory that dataptr points to
		dataptr[i] = 0xff000000 | (0x00010000 * (i % pixsize[0])) | (0x00000100 * (i / pixsize[1]));
	}
	int blits[] = { SCREEN_BLIT_SOURCE_X, 0,
					SCREEN_BLIT_SOURCE_Y, 0,
					SCREEN_BLIT_SOURCE_WIDTH, pixsize[0],
					SCREEN_BLIT_SOURCE_HEIGHT, pixsize[1],
					SCREEN_BLIT_DESTINATION_X, 100,
					SCREEN_BLIT_DESTINATION_Y, 100,
					SCREEN_BLIT_DESTINATION_WIDTH, 400,
					SCREEN_BLIT_DESTINATION_HEIGHT, 400,
					SCREEN_BLIT_END };
	screen_blit(ctx, winbuf, pixbuf, blits);
	screen_post_window(window, winbuf, 1, rect, SCREEN_WAIT_IDLE);

What this does is:

-creates a window 600x600 in size

-creates a pixmap 200x200 in size

-retrieves a pointer to the pixmap data buffer

-renders a pattern into the data buffer

-blits the pixmap onto the window at location (100,100), and scales it to size 400 x 400.

-posts the full window to the screen

 

I may have been a bit overly wordy in my blitting example.. you can blit the entire pixmap scaled to the size of the entire window buffer by just specifying SCREEN_BLIT_END, but I felt the additional information may prove a useful reference for you if you wished to scale or move the pixmap around the window.

 

In your use case, instead of rendering a pattern to the pixmap, you would load your PNG data there instead.

 

Hope this serves as a useful starting point for you.


copies your code from above and it doesn't do anything on BETA 2.1.  It just shows the splash screen and somethings it just exists the app.

 

do you have any simple example on how to just load a jpg/png image and then display it on specific location just like your above code that works on BETA 2.1?