PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

How to display a bitmap ?

MetsDuManche · 09 Jul 2007, 10:59 UTC
Hello,

I'm new in this forum, and new in Edge Lib development. So my question may appear a newbee's one, I'm sorry :)

I need this library to create a rich interface for our mobile software, that may work on the largest scope of phones. I was considering a Java ME development, but it doesn't seem to be able to let me do what I want.

I do believe Edge will be the best choice. I could install the SDK, and start trying to program, using the samples. It works with the emulator and with my phone too (HTC P3600). That's great.

But It's long to understand well how it works. Could you give me a help so that I may display a picture somewhere on the screen ? How can I display a picture 1) from a file on disk and 2) from a file in project resources ? I'm using Visual Studio 2005.

Thanks a lot for your help.
Hi,

To load and display an image I suggest opening the helloworld sample and paste an image inside the release folder (it will be copied in the same folder as the program executable).

In ClassMain, add a new E2DSurface variable as a class member. Load the image file in OnDisplayInit:

Code:

display->CreateSurface(&surface;_var, "image.bmp");


Show it onscreen at OnNextFrame:

Code:

display->BltFast(0, 0, &surface;_var, NULL);


I hope this helps.
MetsDuManche · 09 Jul 2007, 13:13 UTC
Thanks for your fast answer.
Unfortunately, I can't get it working.

I started from the helloworld sample.
In the Main class, I added my global surface variable :

class ClassMain : public ClassEdge
{
public:
ClassMain(const EDGEDATA *data);
~ClassMain(void);
ERESULT OnCreate(EDGECONFIG *config, EDGEDATA *data);
ERESULT OnInit(EINSTANCE instance);
ERESULT OnMinimize(void);
ERESULT OnRestore(void);
ERESULT OnDisplayInit(EINSTANCE instance, ClassEDisplay *display);
ERESULT OnNextFrame(ClassEDisplay *display, unsigned long timedelta);
void OnExit(EINSTANCE instance);
void OnButtonDown(unsigned long bnr, EBUTTONLIST *blist);
void OnButtonUp(unsigned long bnr, EBUTTONLIST *blist);
void OnWheel(long direction);
void OnStylusUp(POINT pnt);
void OnStylusDown(POINT pnt);
void OnStylusDouble(POINT pnt);
void OnStylusMove(POINT pnt);
void OnNetMessage(unsigned char connection, long id, long msg, long bufsize, unsigned char *buffer);
E2DSurface logo;
};


Then, as you suggested, I'm trying to load the picture in "OnDisplayInit()". I converted my picture into a 16 colors bmp file (it was a GIF file before) :

ERESULT ClassMain::OnDisplayInit(EINSTANCE instance, ClassEDisplay *display)
{
display->CreateSurface(&logo;, "titre.bmp");
return(E_OK);
}


Finally, I'm trying to display the picture like this (at the end of function) :

ERESULT ClassMain::OnNextFrame(ClassEDisplay *display, unsigned long timedelta)
{
int nLarg = display->buffer.GetWidth();
int nHaut = display->buffer.GetHeight();
int nCar = 36;
int nBar = 20;
int nMaxIco = nLarg/nCar;
RECT rc;

// Display the title bar
SetRect(&rc;,0,0,nLarg-1,nBar-1);
display->buffer.GradientRectV(&rc;,E_RGBX(0,0,0),E_RGBX(80,80,80),EFX_DITHER);
display->buffer.DrawLine(0,nBar-1,nLarg-1,nBar-1,E_RGBX(192,192,192));
// Display the central screen
SetRect(&rc;,0,nBar,nLarg-1,nHaut-nBar-nCar-1);
display->buffer.GradientRectV(&rc;,E_RGBX(255,255,255),E_RGBX(220,220,220),EFX_DITHER);
display->buffer.DrawFont(nLarg/2, nBar+2, &display-;>fontinternal, "Welcome in StoreXperience!",EFX_COLORKEY | EFO_HCENTER);
display->buffer.DrawFont(nLarg/2, nHaut-nBar-nCar-4, &display-;>fontinternal, "Button/Stylus: Quit", EFX_COLORKEY | EFO_VBOTTOM | EFO_HCENTER);
// Display the command bar
SetRect(&rc;,0,nHaut-nBar,nLarg-1,nHaut-1);
display->buffer.GradientRectV(&rc;,E_RGBX(0,0,0),E_RGBX(80,80,80),EFX_DITHER);
display->buffer.DrawLine(0,nHaut-nBar,nLarg-1,nHaut-nBar,E_RGBX(80,80,80));
// Display the carroussel
SetRect(&rc;,0,nHaut-nBar-nCar,nLarg-1,nHaut-nBar-1);
display->buffer.GradientRectV(&rc;,E_RGBX(200,200,200),E_RGBX(128,128,128),EFX_DITHER);
display->buffer.DrawLine(0,nHaut-nBar-nCar,nLarg-1,nHaut-nBar-nCar,E_RGBX(255,255,255));
SetRect(&rc;,(nLarg/2)-(nCar/2),nHaut-nBar-nCar,(nLarg/2)+(nCar/2),nHaut-nBar-1);
display->buffer.GradientRectV(&rc;,E_RGBX(80,80,80),E_RGBX(0,0,0),EFX_DITHER);

HERE : // Bitmap in title bar
display->BltFast(2, 0, &logo;, NULL);

return(E_OK);
}


Nothing is displayed (no bitmap).
I get an error 1.
What am I doing wrong ?

Thank you again.
Jean-Michel
Hi,

Can you check the return value of CreateSurface? Does it return E_OK?

Maybe you can also try to load the GIF file. It should work as well.
MetsDuManche · 09 Jul 2007, 13:25 UTC
I checked the returned value like this :
if (display->CreateSurface(&logo;, "titre.bmp") != E_OK) return(E_ERROR);;

I get an error, the program ends immediatlely.

Same if I use the GIF file instead.
Hi,

Can you display the error code from CreateSurface?

You can lookup the error codes and see the matching definition in edge.h, near E_ERROR.
MetsDuManche · 09 Jul 2007, 13:44 UTC
The error code is : 1
MetsDuManche · 09 Jul 2007, 14:13 UTC
Oups ... I found the problem.
Doing like you suggest, it works well. I had just a problem while trying in the emulator, because the image file is not copied into the folder (emulator)...
How can I force the project to save this file with the exe in the emulator ?

Thanks for your help.
MetsDuManche · 09 Jul 2007, 14:57 UTC
I have another question... :oops:

How can I set the transparent color of my bitmap ? surface_var.SetColorKey() do not set transparency.

Some more question if I can ?

How can I set the size and the color of the font before I draw text ?

display->buffer.DrawFont(120, 0, &display-;>fontinternal, "Welcome in StoreXperience!",EFX_COLORKEY | EFO_HCENTER);
Hi,

Good to know it worked. For the emulator this may be more complicated as you need to copy the file. Perhaps you can try creating a .CAB setup file of your application including the bitmap picture. Examples and programs needed to create .CAB files are present in the EDGELIB SDK samples.

For transparency set the colorkey. When blitting specify EFX_COLORKEY as a flag. To colorize the font add EFX_COLORIZE as a flag and add an additional parameter with the color you like to use. Because EDGELIB uses rasterized fonts, it's not possible to draw it in different sizes.
MetsDuManche · 10 Jul 2007, 11:49 UTC
Thanks again for your answer.
Transparency works using this flag, it's perfect. I could change the color of the font too.

I had to check the PNT value received by the onStylusDown event, because it is not true if display mode is landscape (x = y, and y = ScreenHeight-x ...).

Is it possible to get a bold effect with the font (for instance by changing the border color like the font color) ?

Where can I find documentation about this ? I don't find what I need in online HTML reference, nor in tutorials or samples.

I also need to know how I can get a picture from resources instead of a file, so that my images may be included in exe file ? This is very important for my application.

Thanks for your support.
Hi,

Can you tell me which device doesn't return the correct stylus coordinates? Is it a landscape device?

Unfortunately, the EDGELIB font drawing functions don't support font effects, such as bold or italic. You will draw the images as they appear in the font image file. You may want to create a seperate font file with the bold effect.

To load resources, you need to manually lock the resource and load from memory. Here is a small sample:
Code:

//Get resource memory
HRSRC resource_loc = FindResource(NULL, "IDB_IMAGE", MAKEINTRESOURCE(RT_BITMAP));
HGLOBAL resource_load = LoadResource(NULL, resource_loc);
LPVOID resource_mem = LockResource(resource_load);
unsigned long resource_mem_size = 234142;//This needs to be set manually

//Create surface
E2DSurface surface;
display->CreateSurface(&surface;, resource_mem, resource_mem_size);
MetsDuManche · 11 Jul 2007, 12:46 UTC
Thank you for the answer. I will try this code, and load different fonts manually to get larger ones.

The device giving wrong stylus touch position is a HTC P3600. When I am in portrait mode, and start the programme, everything is ok. When I start the programme while the device is in landscape mode, display is ok, but stylus reports wrong coordonates (x = y and y = height-x).
I hope it is the same for all devices, otherwise, let me know if you resolved this "problem".

We will soon register for the SDK, because it seems to allow us doing what we need.

Best regards
Hi,

Would you like to make a small test on this device? Call GetSystemRotation from ClassEDisplay and check the return value.

If the device is in portrait mode, it should return ROT_NONE (value 0), and when it is in landscape mode it should return ROT_90DEG (value 1). We suspect there is a problem with this function. Can you tell me which library you're using (2002, 2003 or 2005)?
MetsDuManche · 12 Jul 2007, 15:57 UTC
I made this test :

In portrait mode (standard), I get a rotation of 0.
In landscape mode, I get a rotation of 3.

May this help ?

I'm using Windows Mobile 2005.

Regarding hte loading of images from resources, I couldn't get it working, but I used instead your pack functions that are perfect! I got my pictures in a single resources file, and extract them while starting the application. It's exactly what I needed.
Hi,

Thanks for the information on the Pocket PC screen layout, it will certainly help.

I'm glad the pack functions are suitable for your application. If you decide to create a Symbian build, you can use the packages as well.
MetsDuManche · 13 Jul 2007, 09:33 UTC
Yes, this is the reason why I choosed the package. I do need a portable application (Symbian, Windows Mobile, BlackBerry, ...) and soon Linux Mobile and iPhone ? ;-)

Do you have a date for the iPhone compatibility of the SDK ? ;-)

Can I ask another question ?
I need to create a cool transition effect for a carrousel (like sliding icons with transparency). What function should I use ? How can I animate a part of the screen, let's say a rectangle, to make like if it was sliding ? I couldn't get BltFx() working yet, I didn't understand how to use it.

Best.
Hi,

Unfortunately, we can't give an estimate on iPhone support, because the SDK is currently closed for third party developers. But we're keeping an eye on them.

Regarding the opacity slide effect, you can use BltFast for that. Specify the EFX_OPACITY along with the amount of opacity in the flags and property parameter. Here is an example to blit a picture with 50% opacity and colorkey:

Code:

display->buffer.BltFast(0, 0, &picture;, NULL, EFX_COLORKEY | EFX_OPACITY, 128);
MetsDuManche · 13 Jul 2007, 13:38 UTC
Thank you very much.
Is it possible to get a portion of the screen, then move it to another place ?
Is it possible to resize (stretch) a portion of screen or a picture, to simulate a zoom effect ?

Ok, I found alone. Blt to scale a surface, and BltFast to pickup a screen part, then display it somewhere else.
Hi,

Great that you've found the functions you need.

To grab a part of the surface use the RECT parameter while blitting. This works for both Blt and BltFast.