Reading MBM MIF images
Article Metadata
Class CMBM_MIF_Reader illustrates how to load MBM and MIF images in S60 3rd Edition devices.
Note that IsMifFile-function used to determine if the file if MBM or MIF uses only the file extension to determine the file type, not the actual file content, thus MIF files should always have .mif extension and mbm files .mbm extension.
The ValidateLogicalAppIconId-function is used to map the zero-based index numbers to the actual index numbers used with the mif file, thus you can use zero-based index similarly as with the mbm files.
Also note that some native S60 controls will resize icons automatically, and when the icons are used with these types of controls the aSize argument should indicate size equal to TSize(0,0), which would then allow these controls to do their own resizing.
Link against: aknicon.lib
MBM_MIF_Reader.cpp
#include <aknsutils.h>
#include "MBM_MIF_Reader.h"
CMBM_MIF_Reader::CMBM_MIF_Reader()
{
}
CMBM_MIF_Reader::~CMBM_MIF_Reader()
{
delete iFrameImg;
delete iFrameMsk;
}
void CMBM_MIF_Reader::LoadImageL(const TDesC& aFileName, TInt aImg, TInt aMsk,const TSize& aSize)
{
delete iFrameImg, iFrameImg = NULL;
delete iFrameMsk, iFrameMsk = NULL;
// we should validate icon ID in case of MIF-file
TInt MaskId(aMsk);
TInt UseIndex(aImg);
if(AknIconUtils::IsMifFile(aFileName))
AknIconUtils::ValidateLogicalAppIconId(aFileName, UseIndex, MaskId);
AknIconUtils::CreateIconL(iFrameImg, iFrameMsk, aFileName, UseIndex, MaskId);
AknIconUtils::SetSize(iFrameImg,aSize,EAspectRatioPreserved);
AknIconUtils::SetSize(iFrameMsk,aSize,EAspectRatioPreserved);
}
CFbsBitmap* CMBM_MIF_Reader::Bitmap()
{
return iFrameImg;
}
CFbsBitmap* CMBM_MIF_Reader::Mask()
{
return iFrameMsk;
}
MBM_MIF_Reader.h
#include <e32base.h>
// forward declaration
class CFbsBitmap;
class CMBM_MIF_Reader : public CBase
{
public:
CMBM_MIF_Reader();
~CMBM_MIF_Reader();
void LoadImageL(const TDesC& aFileName, TInt aImg, TInt aMsk,const TSize& aSize);
// accessors
CFbsBitmap* Bitmap();
CFbsBitmap* Mask();
private:
CFbsBitmap* iFrameMsk;
CFbsBitmap* iFrameImg;
};


04 Sep
2009
This article contains source code of the class CMBM_MIF_Reader. With the help of this class you could load and resize icons - very often operations, so it is a good idea to simplify them via this class. The implementation supports both icons containers: MIF and MBM files.
I have successfully used this example in my projects, it helped me to avoid stupid errors. ---