📄 cpictureloader.cpp
字号:
/*
============================================================================
* Name : CPictureLoader.cpp
* Part of : Example3D
* Description : Definition of CPictureLoader
* Copyright (c) 2005 Nokia Corporation
============================================================================
*/
// INCLUDES
#include "CPictureLoader.h"
#include <eikenv.h>
#include <eikappui.h>
#include <eikapp.h>
const TInt KColor16MU = 11; // EColor16MU is not defined in earlier SDK's
// MEMBER FUNCTIONS
CPictureLoader* CPictureLoader::NewL()
{
CPictureLoader* self = new( ELeave )CPictureLoader();
CleanupStack::PushL( self );
self->ConstructL();
CleanupStack::Pop( self );
return self;
}
CPictureLoader::~CPictureLoader()
{
}
void CPictureLoader::ConstructL()
{
#ifndef __SERIES60_3X__
TFileName appFullName = CEikonEnv::Static()->EikAppUi()->Application()->AppFullName();
TParse parse;
//On WINS the application is on the z drive
#ifdef __WINS__
parse.Set(_L("c:"), &appFullName, NULL);
#else
parse.Set( appFullName, NULL, NULL);
#endif
iPath = parse.DriveAndPath();
#else
RFs fs;
User::LeaveIfError(fs.Connect());
fs.PrivatePath(iPath);
fs.Close();
#endif
}
CPictureLoader::CPictureLoader()
{
}
TBitmap CPictureLoader::LoadL( const TFileName& aFileName, TDisplayMode aDisplayMode )
{
TFileName file( iPath );
file.Append( aFileName );
CFbsBitmap bitmap;
iStatus = KErrNone;
CMdaImageFileToBitmapUtility* util;
util = CMdaImageFileToBitmapUtility::NewL( *this ) ;
CleanupStack::PushL( util );
util->OpenL( file );
iWait.Start();
User::LeaveIfError( iStatus );
TFrameInfo frameInfo;
util->FrameInfo( 0, frameInfo );
User::LeaveIfError( bitmap.Create( frameInfo.iOverallSizeInPixels, aDisplayMode ) );
util->ConvertL( bitmap );
iWait.Start();
User::LeaveIfError( iStatus );
CleanupStack::PopAndDestroy( util );
TBitmap bm;
bm.iSize = bitmap.SizeInPixels();
TInt pixels = bm.iSize.iWidth * bm.iSize.iHeight;
// copy loaded bitmap pixels into the internal structures
if (aDisplayMode == KColor16MU)
{
// 32 bit pixels - copy color components and set alpha channel to 255
bm.iData = new( ELeave )TUint8[ pixels * 4 ];
bm.iMode = EColor16MU;
bitmap.LockHeap(EFalse);
TUint8* source = (TUint8*)bitmap.DataAddress();
TUint8* destination = (TUint8*)bm.iData;
TInt i;
for (i=0; i<pixels; i++)
{
#ifdef GLES
// switch color components for the OpenGL textures
destination[0] = source[2];
destination[2] = source[0];
#else
destination[0] = source[0];
destination[2] = source[2];
#endif
destination[1] = source[1];
destination[3] = 255;
destination += 4;
source += 4;
}
bitmap.UnlockHeap(EFalse);
}
else
{
// 16 bit pixels
bm.iData = new( ELeave )TUint16[ pixels ];
bm.iMode = aDisplayMode;
TInt y;
for( y=0; y<bm.iSize.iHeight; y++ )
{
TPtr8 ydata( ((TUint8*)bm.iData) + y * bm.iSize.iWidth * 2, bm.iSize.iWidth * 2 );
bitmap.GetScanLine( ydata, TPoint( 0, y ), bm.iSize.iWidth, aDisplayMode );
}
}
return bm;
}
void CPictureLoader::MiuoConvertComplete( TInt aError )
{
iStatus = aError;
iWait.AsyncStop();
}
void CPictureLoader::MiuoCreateComplete( TInt /*aError*/ )
{
// manual create...
}
void CPictureLoader::MiuoOpenComplete( TInt aError )
{
iStatus = aError;
iWait.AsyncStop();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -