First, this control class is provided:
Header file:
# Ifndef cmypicture_h
# Define cmypicture_h
// Des
# Include <e32std. h>
# Include <e32base. h>
# Include <f32file. h>
# Include <FBS. h>
# Include <coecntrl. h>
// Class declaration
// Class RFS;
Class cmypicture: Public ccoecontrol
{
Public: // constructors and destructor
/**
* Destructor.
*/
~ Cmypicture ();
/**
* Two-phased constructor.
*/
Static cmypicture * newl ();
/**
* Two-phased constructor.
*/
Static cmypicture * newlc ();
Public:
/**
* Constructor for Ming 1st Stage Construction
*/
Cmypicture ();
/**
* EPOC default constructor for faster Ming 2nd Stage Construction
*/
Void constructl ();
Virtual void draw (const trect & arect) const;
Void setpicture (tdesc & afilepath );
Void setvisiable (tbool avisiable );
Void getpng (RFS & AFS, const tdesc & afilepath, cfbsbitmap * ibitmap, cfbsbitmap * ibmpmask );
PRIVATE:
Tbuf <100> ifilepath;
Rfs fs;
Cfbsbitmap * ibitmapback;
Cfbsbitmap * ibitmapbackmask;
Tbool ibvisiable;
};
# Endif // cmypicture_h
Then the CPP file:
# Include "cmypicture. H"
# Include <eikenv. h>
# Include <imageconversion. h>
Cmypicture: cmypicture ()
{
// No implementation required
}
Cmypicture ::~ Cmypicture ()
{
}
Cmypicture * cmypicture: newlc ()
{
Cmypicture * Self = new (eleave) cmypicture ();
Cleanupstack: pushl (Self );
Self-> constructl ();
Return self;
}
Cmypicture * cmypicture: newl ()
{
Cmypicture * Self = cmypicture: newlc ();
Cleanupstack: Pop (); // self;
Return self;
}
Void cmypicture: constructl ()
{
Createmediawl ();
FS = ieikonenv-> fssession ();
Ibitmapback = new (eleave) cfbsbitmap ();
Ibitmapbackmask = new (eleave) cfbsbitmap ();
_ Configure (kbackpath, "C: \ System \ apps \ SG \ back2.png ");
Getpng (FS, kbackpath, ibitmapback, ibitmapbackmask );
Ibvisiable = etrue;
}
Void cmypicture: setpicture (tdesc & afilepath)
{
Ifilepath = afilepath;
}
Void cmypicture: setvisiable (tbool avisiable)
{
Ibvisiable = avisiable;
Drawnow ();
}
Void cmypicture: getpng (RFS & AFS, const tdesc & afilepath, cfbsbitmap * ibitmap, cfbsbitmap * ibmpmask)
{
_ Lit8 (mimetype, "image/PNG ");
Cimagedecoder * imagedecoder = cimagedecoder: filenewl (AFS, afilepath,
Mimetype,
Cimagedecoder: eoptionalwaysthread
);
Ibitmap-> Create (imagedecoder-> frameinfo (). ioverallsizeinpixels,
Imagedecoder-> frameinfo (). iframedisplaymode/* was ecolor4k */);
// Its a ecolor16m
Ibmpmask-> Create (imagedecoder-> frameinfo (). ioverallsizeinpixels, egray256/* was egray2 */);
Trequeststatus status;
Imagedecoder-> convert (& status, * ibitmap, * ibmpmask );
User: waitforrequest (Status );
Delete imagedecoder;
}
Void cmypicture: Draw (const trect & arect) const
{
Cwindowgc & GC = systemgc ();
If (ibvisiable)
{
Trect BMP emapiecerect (tpoint (0, 0), ibitmapback-> sizeinpixels ());
GC. bitbltmasked (tpoint (10, 10), ibitmapback, BMP emapiecerect, ibitmapbackmask, etrue );
}
}
You can use this class to implement custom image controls.