PocketMagic

PocketMagic

Where Technology meets magic


Android
45 Posts
BlackBerry
4 Posts
Electronics
68 Posts
Hardware
120 Posts
High Voltage
49 Posts
iPhone
4 Posts
Linux
2 Posts
Nuclear
20 Posts
Optics
11 Posts
Photography
7 Posts
Photoshop
3 Posts
Research
19 Posts
Reviews
18 Posts
Robotics
8 Posts
Security
7 Posts
Software
73 Posts
Symbian
2 Posts
Tubes
18 Posts
Windows
3 Posts
Windows Mobile
11 Posts

Top Articles!       See PocketMagic on Facebook


uRADMonitor - Online Radiation monitoring station | 14905 Views | Rate 70.31
uRADMonitor - Online Radiation monitoring station
Bluetooth and iOS - Use Bluetooth in your iPhone apps | 18049 Views | Rate 58.41
Bluetooth and iOS - Use Bluetooth in your iPhone apps
NMEA GPS Library for AVR Microcontrollers | 4814 Views | Rate 56.64
NMEA GPS Library for AVR Microcontrollers
Programmatically Injecting Events on Android - Part 2 | 4973 Views | Rate 44.8
Programmatically Injecting Events on Android - Part 2
Building a robot – Part 2 | 4594 Views | Rate 44.6
Building a robot – Part 2
Simple Switched power Supplies | 16102 Views | Rate 41.82
Simple Switched power Supplies
Capacitor Discharge Microspot Welder / Cutter | 11308 Views | Rate 36.36
Capacitor Discharge Microspot Welder / Cutter
Atmega8 and Nokia 5110 LCD  | 1525 Views | Rate 35.47
Atmega8 and Nokia 5110 LCD

 
  

Handle drawing in Symbian


By Meda Posted on May 13th, 2009 , 498 Views (Rate 0.34)



  




This article will show how to draw an image and shapes in your Symbian application.
Will start from the Hello World project described in the previous article.

First thing to do is chose an image, open it in Paint and save it as you desire(256 color, 24bit bmp) just remember
this information, to use it later on.Save the images to the group directory where the mmp file is.

You need 3 file to be able to load an image: *.mmp , *.mbm and *.mbg file

1.MMP file

The *.mmp file that is file that is located in the group directory of your project,
besides listing the desired mbm files you also can add lib files,
more information about mmp files and other symbian project components you can find on nokia forum:

http://www.forum.nokia.com

Right click on mmp file and select Open with->Text editor to view it's content.

You should add the following lines to the mmp file:

START BITMAP test7.mbm
TARGETPATH \resource\apps
HEADER
SOURCE c24 smiley.bmp smilmask.bmp
END

The mbm file should be named after the application(my application is test7 so I named it test7.mbm).
c24 is the type of bmp - 24bit bmp file.
eg. if your bmp is 24bit, than use c24
if your bmp if 256color, 256color=2^8 -> 8bit, this means you'll have to use c8
...and so on
smiley.bmp, smilmask.bmp the name of the bmp files, you can add as many as you like.

After you've added this to the mmp file, recompile,
and the mbm and mbg files will be automatically created.

2.MBM file

MBM - multi bitmap file used by Carbide to load the images, this file can contain multiple bitmaps.

You can either create this file yourself from some known photo design applications like PhotoShop or
let Carbide create it with some simple lines inserted in *.mmp file at compilation process(this is the method I've chosen).
If you change the images you'll have first to delete this file from where is created so that it takes the new bmp, at
least this is what it happened to me, otherwise it didn't create the new mbm. You will also need to comment the parts
from the code that refer to the image ids for the compilation to take place.

Where is the MBM file located?
You don't really need this information, at least not for this purpose, as at compilation process carbide takes it
from where it has saved it, mine was located in:

c:\Symbian\9.1\S60_3rd_MR\Epoc32\Data\z\resource\apps\

, anyway the location is different from a platform to another, you'll have to serch for it somewhere in
c:\Symbian\9.1\S60_3rd_MR\Epoc32 if you want to know it's location for sure. I guess it depends on
EPOCROOT, platform, TARGETPATH..I didn't bother too much about this.

3.MBG file

This file contains the ids for the bmp files, that you'll use later in the application for loading them.
As I mentioned earlier this file is created on compilation procces. Mine was created in:

c:\Symbian\9.1\S60_3rd_MR\Epoc32\BUILD\work\Symbian\test7\group\test7\GCCE\
and in
c:\Symbian\9.1\S60_3rd_MR\Epoc32\include\

Don't modify this file! if you do, it won't work anymore, let Carbide create it.
Once it is created you can include the file in your project:

#include <*.mbg>

then you can use the ids, my ids are:

EMbmTest7Smiley and EMbmTest7Smilmask

If you delete this file you'll need to comment the parts of the code were the ids are used and where it is included,
and also delete the mbm file(otherwise it will not be created), in order to recompile the code and the mbm and mbg
files to be created once again.

4.The code:

Include first the mbg file:

#include *.mbg;





I specially made a class for loading and drawing the bmp files.
Here are some snippets from the class I've created:

void CImageHandle::LoadBitmap(const TDesC& aPathAndFile,TInt aId)
{
TParse mbfn;
mbfn.Set(aPathAndFile,&KTxtCDrive,NULL);

if(aId == EMbmTest7Smiley)
iBitmap->Load(mbfn.FullName(),aId);
else if(aId == EMbmTest7Smilmask)
iMaskBitmap->Load(mbfn.FullName(),aId);

return;
}

void CImageHandle::Draw(CWindowGc& aGc,const TDesC& aPathAndFile,TInt aId,TInt aIdMask)
{
iBitmap = new (ELeave) CFbsBitmap();
iMaskBitmap = new (ELeave) CFbsBitmap();

LoadBitmap(aPathAndFile,aId);
LoadBitmap(aPathAndFile,aIdMask);

// set a rectangle for the top-left quadrant of the source bitmap
TSize bmpSizeInPixels=iBitmap->SizeInPixels();
TSize bmpPieceSize(bmpSizeInPixels.iWidth,bmpSizeInPixels.iHeight);
TRect bmpPieceRect(TPoint(0,0),bmpPieceSize);

TPoint pos(20,20);

aGc.BitBlt(pos, iBitmap);
//aGc.DrawBitmap(bmpPieceRect,iBitmap);
//aGc.BitBltMasked(pos,iBitmap,bmpPieceRect,iMaskBitmap,EFalse);
}

And here is the code for the drawing event:

void Ctest7AppView::Draw(const TRect& /*aRect*/) const
{
CImageHandle* Ctest7DrawObj;

// Get the standard graphics context
CWindowGc& gc = SystemGc();

// Gets the control's extent
TRect drawRect(Rect());

// Clears the screen
gc.Clear(drawRect);

Ctest7DrawObj = new ( ELeave ) CImageHandle;
Ctest7DrawObj->Draw(gc,KTxtMBMname,EMbmTest7Smiley,EMbmTest7Smilmask);

TPoint startPoint(50,50);
TPoint endPoint(590,190);

gc.DrawLine(startPoint,endPoint);

}

Besides displaying the image it also draws a line, it's very simple, other shapes as well.

In order for this code to work you'll have to include some libs:hlplch.lib fbscli.lib bafl.lib

And here is the result:

Source code: drawimagearticle

5. How to add a lib file?

You can open the mmp file in carbide and there you have the option to add a lib file, or simply edit it in
notepad.

It is a good idea to start learning about Exception Handling as these are often used in Symbian programming,
I didn't use them as I don't know how they work at this moment, it looked simple but when I've used them something
went wrong so I didn't investigate it anymore, I worked without them. I would appreciate if someone who has the knowledge
would write a few lines about this. Here are some links that might help:

http://www.newlc.com/Exception-Handling-and-Cleanup.html
http://www.newlc.com/LEAVE-and-TRAP.html

By Meda Chiorean






  

More on PocketMagic:

Developing for Blackberry 10 | 76 Views | Rate 25.33
Developing for Blackberry 10
Atmega8 and enc28J60 for ethernet support | 7246 Views | Rate 24.56
Atmega8 and enc28J60 for ethernet support
How to set the AVR Fusebits | 1702 Views | Rate 23.97
How to set the AVR Fusebits
ATMega128 and HD44780 LCD using 3 Wires with the 74HC164 | 2046 Views | Rate 22.99
ATMega128 and HD44780 LCD using 3 Wires with the 74HC164
Dual H-Bridge for controlling two motors | 1191 Views | Rate 21.65
Dual H-Bridge for controlling two motors
Tube: 1B40 | 255 Views | Rate 21.25
Tube: 1B40

Thank you for commenting. Your comment won't show until approved, which can take some time.

Please copy the string D6nMn9 to the field below: