📄 bmpmanipappview.cpp
字号:
/* Copyright (c) 2003, Nokia Mobile Phones. All rights reserved */
#include <eikenv.h>
#include <gdi.h>
#include "BmpmanipAppView.h"
#include "EikonEnvironment.h"
// File to load in
_LIT(KGifFileName,"c:\\System\\Apps\\Bmpmanip\\image1.gif");
// File to save
_LIT(KBmpFileName,"c:\\System\\Apps\\Bmpmanip\\newimage.bmp");
const TDisplayMode KDeviceColourDepth = EColor4K;
// Gif file frame index (in this case there is only one frame)
const TInt KGifFrameIndex = 0;
// New size to scale image
const TInt KNewImageWidth = 150;
const TInt KNewImageHeight = 150;
CBmpmanipAppView* CBmpmanipAppView::NewL(const TRect& aRect)
{
CBmpmanipAppView* self = NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
CBmpmanipAppView* CBmpmanipAppView::NewLC(const TRect& aRect)
{
CBmpmanipAppView* self = new (ELeave) CBmpmanipAppView;
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
void CBmpmanipAppView::ConstructL(const TRect& aRect)
{
// Create a window for this application view
CreateWindowL();
// Set the windows size
SetRect(aRect);
// Activate the window, which makes it ready to be drawn
ActivateL();
iBitmap = new (ELeave) CFbsBitmap();
iRotator = CMdaBitmapRotator::NewL();
iFileSaver = CMdaImageBitmapToFileUtility::NewL(*this);
iScaler = CMdaBitmapScaler::NewL();
iConverter = CMdaImageFileToBitmapUtility::NewL(*this);
//Start an asynchronous process to open the gif file
iConverter->OpenL(KGifFileName);
}
CBmpmanipAppView::CBmpmanipAppView()
: iConvertState(EConvertStateNull)
{
// No implementation required
}
CBmpmanipAppView::~CBmpmanipAppView()
{
delete iFileSaver;
iFileSaver = NULL;
delete iRotator;
iRotator = NULL;
delete iScaler;
iScaler = NULL;
delete iConverter;
iConverter = NULL;
delete iBitmap;
iBitmap = NULL;
}
void CBmpmanipAppView::Draw(const TRect& /*aRect*/) const
{
//Clear the screen
CWindowGc& gc = SystemGc();
gc.Clear(Rect());
//If the bitmap is not currently being processed in any way
if (iConvertState == EConvertStateReady || iConvertState == EConvertStateSaving)
{
gc.BitBlt(Rect().iTl,iBitmap);
}
}
void CBmpmanipAppView::RotateImageClockwiseL(TImageRotateAngle aAngle)
{
if (iConvertState != EConvertStateReady)
{
//Inform the UI that the gif file is still being loaded
User::Leave(KErrInUse);
}
switch (aAngle)
{
case E90Degrees:
//Start an asynchronous process to rotate the bitmap
iRotator->RotateL(*this,*iBitmap,CMdaBitmapRotator::ERotation90DegreesClockwise);
iConvertState = EConvertStateRotating;
break;
case E180Degrees:
//Start an asynchronous process to rotate the bitmap
iRotator->RotateL(*this,*iBitmap,CMdaBitmapRotator::ERotation180DegreesClockwise);
iConvertState = EConvertStateRotating;
break;
case E270Degrees:
//Start an asynchronous process to rotate the bitmap
iRotator->RotateL(*this,*iBitmap,CMdaBitmapRotator::ERotation270DegreesClockwise);
iConvertState = EConvertStateRotating;
break;
default:
ASSERT(FALSE);
}
}
void CBmpmanipAppView::SaveL()
{
if (iConvertState != EConvertStateReady)
{
return;
}
//Start an asyncronous process to create a file for the bitmap
//Note this does not save the actual bitmap - this is done once the file has been created
iFileSaver->CreateL(KBmpFileName,&iClipFormat,&iCodec,&iCodec);
iConvertState = EConvertStateSaving;
}
void CBmpmanipAppView::MiuoOpenComplete(TInt aError)
{
_LIT(KConnectErrTxt, "Could not connect to font and bitmap server");
_LIT(KSizeErrTxt, "Illegal Gif file size");
_LIT(KConverterErrTxt, "Cannot initiate converter");
_LIT(KInsufficientInfoErrTxt, "Gif file contains insufficient information, cannot retry");
_LIT(KFileErrTxt, "Error opening file");
if (aError == KErrNone)
{
iConvertState = EConvertStateConvertingFromGif;
TFrameInfo frameInfo;
//Get the frame info
iConverter->FrameInfo(KGifFrameIndex,frameInfo);
//Create a bitmap based on the size of the gif
TInt err = iBitmap->Create(frameInfo.iOverallSizeInPixels,KDeviceColourDepth);
if (err == KErrCouldNotConnect)
{
NEikonEnvironment::MessageBox(KConnectErrTxt);
return;
}
if (err == KErrArgument)
{
NEikonEnvironment::MessageBox(KSizeErrTxt);
return;
}
//Convert the gif into a bitmap
TRAPD(convertErr,iConverter->ConvertL(*iBitmap,KGifFrameIndex));
//Trap error as this function cannot leave
if (convertErr != KErrNone)
{
NEikonEnvironment::MessageBox(KConverterErrTxt);
}
}
else if (aError == KErrUnderflow)
{
//This error occurs if the gif file contains insufficient information
//This is usually because the file is being opened in a cache so a futher attempt to open
//should be performed
TRAPD(err,iConverter->OpenL(KGifFileName));
if (err !=KErrNone)
{
NEikonEnvironment::MessageBox(KInsufficientInfoErrTxt);
}
}
else
{
NEikonEnvironment::MessageBox(KFileErrTxt);
}
}
void CBmpmanipAppView::MiuoConvertComplete(TInt aError)
{
switch (iConvertState)
{
//Finished converting gif file to bitmap
case EConvertStateConvertingFromGif:
ConvertingFromGifFinished(aError);
break;
//Finished saving file
case EConvertStateSaving:
SavingFinished(aError);
break;
//Finished Scaling file
case EConvertStateScaling:
ScalingFinished(aError);
break;
//Finished Rotating file
case EConvertStateRotating:
RotatingFinished(aError);
break;
case EConvertStateNull:
default:
ASSERT(FALSE);
}
}
void CBmpmanipAppView::MiuoCreateComplete(TInt aError)
{
_LIT(KConvertErrTxt, "Conversion could not be started");
_LIT(KCreateErrTxt, "File Could not be created");
if (aError == KErrNone)
{
//Now the bitmap file has been created, write the bitmap to it
TRAPD(err,iFileSaver->ConvertL(*iBitmap));
if (err != KErrNone)
{
NEikonEnvironment::MessageBox(KConvertErrTxt);
}
}
else
{
//Reset state so that other operations can still be performed
iConvertState = EConvertStateReady;
NEikonEnvironment::MessageBox(KCreateErrTxt);
}
}
void CBmpmanipAppView::ConvertingFromGifFinished(TInt aError)
{
_LIT(KScaleErrTxt, "Cannnot re scale image");
_LIT(KConvertErrTxt, "Error converting file");
if (aError == KErrNone)
{
TRAPD(err,iScaler->ScaleL(*this,*iBitmap,TSize(KNewImageWidth,KNewImageHeight)));
if (err == KErrNone)
{
iConvertState = EConvertStateScaling;
}
else
{
NEikonEnvironment::MessageBox(KScaleErrTxt);
}
}
else
{
NEikonEnvironment::MessageBox(KConvertErrTxt);
}
}
void CBmpmanipAppView::SavingFinished(TInt aError)
{
_LIT(KFileSaveTxt, "File Saved");
_LIT(KFileSaveErrTxt, "Error saving image");
if (aError == KErrNone)
{
iConvertState = EConvertStateReady;
NEikonEnvironment::MessageBox(KFileSaveTxt);
}
else
{
NEikonEnvironment::MessageBox(KFileSaveErrTxt);
}
}
void CBmpmanipAppView::ScalingFinished(TInt aError)
{
_LIT(KResizeErrTxt, "Error resizing image");
if (aError == KErrNone)
{
iConvertState = EConvertStateReady;
DrawNow();
}
else
{
NEikonEnvironment::MessageBox(KResizeErrTxt);
}
}
void CBmpmanipAppView::RotatingFinished(TInt aError)
{
_LIT(KRotateErrTxt, "Error rotating image");
if (aError == KErrNone)
{
iConvertState = EConvertStateReady;
DrawNow();
}
else
{
NEikonEnvironment::MessageBox(KRotateErrTxt);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -