Primero dé esta clase de control:
head Archivo:
#ifndef CMyPicture_H
#define CMyPicture_H
// INCLUYE
#include <e32std.h>
#include <e32base.h>
#include <f32file.h>
#include <fbs.h>
#include <coecntrl.h>
// DECLARACIÓN DE CLASE
// clase RFs;
class CMyPicture: public CCoeControl
{ public: // Constructores y destructor
/ **
* Destructor.
* /
~ CMyPicture ();
/ **
* Constructor de dos fases.
* /
CMyPicture estática * NewL ();
/ **
* Constructor de dos fases.
* /
CMyPicture estática * NewLC ();
público:
/ **
* Constructor para realizar la construcción de la 1ª etapa
* /
CMyPicture ();
/ **
* Constructor predeterminado de EPOC para realizar la construcción de la segunda etapa
* /
void ConstructL ();
vacío virtual Draw (const TRect & aRect) const;
Void SetPicture (TDesC & aFilePath);
void SetVisiable (TBool aVisiable);
void GetPng (RFs y aFs, const TDesC y afilepath, CFbsBitmap * iBitmap, CFbsBitmap * iBmpMask);
privado:
TBuf <100> iFilePath;
RFs fs;
CFbsBitmap * iBitmapBack;
CFbsBitmap * iBitmapBackMask;
TBool iBVisiable;
};
#endif // CMyPicture_H
Luego, el archivo cpp:
#include "CMyPicture.h"
#include <eikenv.h>
#include <ImageConversion.h>
CMyPicture :: CMyPicture ()
{ // No se requiere implementación }
CMyPicture :: ~ CMyPicture ()
{ }
CMyPicture * CMyPicture :: NewLC ()
{ CMyPicture * self = nuevo (ELeave) CMyPicture (); CleanupStack :: PushL (self); self-> ConstructL (); volver a sí mismo; }
CMyPicture * CMyPicture :: NewL ()
{ CMyPicture * self = CMyPicture :: NewLC (); CleanupStack :: Pop (); // uno mismo; volver a sí mismo; }
void CMyPicture :: ConstructL ()
{
CreateWindowL ();
fs = iEikonEnv-> FsSession ();
iBitmapBack = nuevo (ELeave) CFbsBitmap ();
iBitmapBackMask = new (ELeave) CFbsBitmap ();
_LIT (KBackPath, "c: //sistema//apps//SG//back2.png");
GetPng (fs, KBackPath, iBitmapBack, iBitmapBackMask);
iBVisiable = ETrue;
}
anular CMyPicture :: SetPicture (TDesC y aFilePath)
{ iFilePath = aFilePath;
}
anular CMyPicture :: SetVisiable (TBool aVisiable)
{ iBVisiable = aVisiable; DrawNow (); }
void CMyPicture :: GetPng (RFs y aFs, const TDesC y afilepath, CFbsBitmap * iBitmap, CFbsBitmap * iBmpMask)
{ _LIT8 (MimeType, "imagen / png"); CImageDecoder * imageDecoder = CImageDecoder :: FileNewL (aFs, afilepath, MimeType, CImageDecoder :: EOptionAlwaysThread ); iBitmap-> Create (imageDecoder-> FrameInfo (). iOverallSizeInPixels, imageDecoder-> FrameInfo (). iFrameDisplayMode / * era EColor4K * /); // es un EColor16M iBmpMask-> Create (imageDecoder-> FrameInfo (). iOverallSizeInPixels, EGray256 / * era EGray2 * /); TRequestStatus status; imageDecoder-> Convertir (& estado, * iBitmap, * iBmpMask); Usuario :: WaitForRequest (estado); eliminar imageDecoder;
}
anular CMyPicture :: Draw (const TRect & aRect) const
{ CWindowGc & gc = SystemGc (); if (iBVisiable) { TRect bmpEmaPieceRect (TPoint (0,0), iBitmapBack-> SizeInPixels ()); gc.BitBltMasked (TPoint (10,10), iBitmapBack, bmpEmaPieceRect, iBitmapBackMask, ETrue); }
}
Utilice esta clase para implementar controles de imagen personalizados.