⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imageconversionview.cpp

📁 《UIQ 3 The Complete Guide》书的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
// ImageConversionView.cpp - Image Conversion Library interfacing
//
// Copyright (C) UIQ Technology AB, 2007
//
// This material is provided "as is" without any warranty to its performance or functionality. 
// In no event shall UIQ Technology be liable for any damages whatsoever arising out of the
// use or inabilty to use this material. 
//

#include "ImageConversionView.h"
#include "SignedAppUids.h"
#include "SignedApp.hrh"
#include <SignedApp_0x20000462.rsg>

#include <QikCommand.h>
#include <QikAppUi.h>
#include <QikApplication.h>
#include <eikchlst.h>
#include <eikdialg.h>
#include <eikedwin.h>

#include <ImageConversion.h>
#include <BitmapTransforms.h>
#include <VideoPlayer.h>

//////////////////////////////////////////////////////////////////////////////////////////
class CImageDisplayControl;

class CImageLoader : public CActive
	{
protected:
	// from CActive
	void RunL();
	void DoCancel();
	
public:
	~CImageLoader();
	CImageLoader(CImageDisplayControl& aDisplay);
	void StartLoadImageL(const TFileName& aFileName);
protected:
	CImageDisplayControl& iDisplay;
	CImageDecoder* iLoader;
	CFbsBitmap* iBitmap;
	};

//////////////////////////////////////////////////////////////////////////////////////////
class CImageRotator : public CActive
	{
protected:
	// from CActive
	void RunL();
	void DoCancel();
	
public:
	~CImageRotator();
	CImageRotator(CImageDisplayControl& aDisplay);
	void StartRotateImageL(CFbsBitmap* aBitmap);
protected:
	CImageDisplayControl& iDisplay;
	CBitmapRotator* iRotator;
	CFbsBitmap* iBitmap;
	};

//////////////////////////////////////////////////////////////////////////////////////////
class CImageSaver : public CActive
	{
protected:
	// from CActive
	void RunL();
	void DoCancel();
	
public:
	~CImageSaver();
	CImageSaver(CImageDisplayControl& aDisplay);
	void StartSaveImageL(const TFileName& aFileName,const TUid& aImageType,const TUid& aImageSubType,CFbsBitmap* aBitmap);
protected:
	CImageDisplayControl& iDisplay;
	CImageEncoder* iSaver;
	};

//////////////////////////////////////////////////////////////////////////////////////////
class CImageDisplayControl : public CCoeControl
	{
protected:
	// from CCoeControl
	void Draw(const TRect& aRect) const;

	friend class CImageLoader;
	void LoadComplete(const TInt aErr,CFbsBitmap* aBitmap);

	friend class CImageRotator;
	void RotateComplete(const TInt aErr,CFbsBitmap* aBitmap);

	friend class CImageSaver;
	void SaveComplete(const TInt aErr);

public:
	// new methods
	~CImageDisplayControl();
	CImageDisplayControl(CAppEngine* aEngine);
	void ConstructL();
	void NewImageSelectedL();
	void CloseImage();
	void RotateImageL();
	void SaveImageL(const TFileName& aDrive);
protected:
	CAppEngine* iEngine;
	CImageLoader* iImageLoader;
	CImageRotator* iImageRotator;
	CImageSaver* iImageSaver;
	CFbsBitmap* iBitmap;
	TFileName iFileName;
	};

//////////////////////////////////////////////////////////////////////////////////////////
CImageLoader::~CImageLoader()
	{
	Cancel();
	}

CImageLoader::CImageLoader(CImageDisplayControl& aDisplay) :
	CActive(CActive::EPriorityStandard),iDisplay(aDisplay)
	{
	// this cant leave so is totally reasonable to call within the constructor.
	CActiveScheduler::Add(this);
	}

void CImageLoader::StartLoadImageL(const TFileName& aFileName)
//
// Start loading the image from the indicated file.
// This version does not use the cleanup stack to store temp object handles so has to manually handle 
// resource tidying up on errors.
//
	{
	// We might want to check state - especially those that can lead to difficult to track
	// down alloc heaven type bugs.
#ifdef _DEBUG
	_LIT(KCImageLoader,"CImageLoader");
#endif
	__ASSERT_DEBUG(iLoader==NULL,User::Panic(KCImageLoader,0));
	__ASSERT_DEBUG(iBitmap==NULL,User::Panic(KCImageLoader,1));

	// create the image loader
	iLoader=CImageDecoder::FileNewL(CEikonEnv::Static()->FsSession(),aFileName);

	// create a bitmap within which to store the loaded image.
	TFrameInfo frameInfo(iLoader->FrameInfo(0));
	TInt ret=KErrNoMemory;
	iBitmap=new CFbsBitmap();
	if (iBitmap)
		{
		if (frameInfo.iFlags&TFrameInfo::ECanDither)
			ret=iBitmap->Create(frameInfo.iOverallSizeInPixels,CEikonEnv::Static()->ScreenDevice()->DisplayMode());
		else
			ret=iBitmap->Create(frameInfo.iOverallSizeInPixels,frameInfo.iFrameDisplayMode);
		}

	if (ret!=KErrNone)
		{
		delete(iBitmap);
		iBitmap=NULL;
		delete(iLoader);
		iLoader=NULL;
		User::Leave(ret);
		}

	// start loading the image into our bitmap. RunL() called when complete
	iLoader->Convert(&iStatus,*iBitmap,0);
	SetActive();
	}
/*
void CImageLoader::StartLoadImageL(const TFileName& aFileName)
//
// Alternative version of StartLoadImageL() that uses the CleanupStack to deal with
// error handling.
//
	{
	// We might want to check state - especially those that can lead to difficult to track
	// down alloc heaven type bugs.
	_LIT(KCImageLoader,"CImageLoader");
	__ASSERT_DEBUG(iLoader==NULL,User::Panic(KCImageLoader,0));
	__ASSERT_DEBUG(iBitmap==NULL,User::Panic(KCImageLoader,1));

	// create the image loader
	CImageDecoder* decoder=CImageDecoder::FileNewL(CEikonEnv::Static()->FsSession(),aFileName);
	CleanupStack::PushL(decoder);

	// create a bitmap within which to store the loaded image.
	TFrameInfo frameInfo(decoder->FrameInfo(0));
	CFbsBitmap* bmp=new(ELeave)CFbsBitmap();
	CleanupStack::PushL(bmp);
	if (frameInfo.iFlags&TFrameInfo::ECanDither)
		User::LeaveIfError(bmp->Create(frameInfo.iOverallSizeInPixels,CEikonEnv::Static()->ScreenDevice()->DisplayMode()));
	else
		User::LeaveIfError(bmp->Create(frameInfo.iOverallSizeInPixels,frameInfo.iFrameDisplayMode));

	// only now we cant leave can we take ownership of the objects in object property
	iBitmap=bmp;
	iLoader=decoder;
	CleanupStack::Pop(2);

	// start loading the image into our bitmap. RunL() called when complete
	iLoader->Convert(&iStatus,*iBitmap,0);
	SetActive();
	}
*/

void CImageLoader::RunL()
// The load operation has completed, sucessfully or otherwise. Inform our view so it can
// update its display of the image.
	{
	iDisplay.LoadComplete(iStatus.Int(),iBitmap); // pass ownership of iBitmap (incl if error)
	iBitmap=NULL; // we no longer own it
	delete(iLoader);
	iLoader=NULL;
	}

void CImageLoader::DoCancel()
// Cancel the image loading. By defn is called when we are IsActive().
// Stop loading the image + tidy up resources so we support a subsequent StartLoadImageL() 
	{
	iLoader->Cancel();
	delete(iBitmap);
	iBitmap=NULL;
	delete(iLoader);
	iLoader=NULL;
	}

//////////////////////////////////////////////////////////////////////////////////////////
CImageRotator::~CImageRotator()
	{
	Cancel();
	}

CImageRotator::CImageRotator(CImageDisplayControl& aDisplay) :
	CActive(CActive::EPriorityStandard),iDisplay(aDisplay)
	{
	// this cant leave so is totally reasonable to call within the constructor.
	CActiveScheduler::Add(this);
	}

void CImageRotator::StartRotateImageL(CFbsBitmap* aBitmap)
// Start rotating the image.
	{
	iRotator=CBitmapRotator::NewL();
	
	// take ownership now we cant leave.
	iBitmap=aBitmap;

	// start rotating the image into our bitmap. RunL() called when complete
	iRotator->Rotate(&iStatus,*iBitmap,CBitmapRotator::ERotation90DegreesClockwise);
	SetActive();
	}

void CImageRotator::RunL()
// The rotate operation has completed, sucessfully or otherwise. Inform our view so it can
// update its display of the image.
	{
	iDisplay.RotateComplete(iStatus.Int(),iBitmap); // pass ownership of iBitmap (incl if error)
	iBitmap=NULL; // we no longer own it
	delete(iRotator);
	iRotator=NULL;
	}

void CImageRotator::DoCancel()
// Cancel the image rotation. By defn is called when we are IsActive().
	{
	iRotator->Cancel();
	delete(iBitmap);
	iBitmap=NULL;
	delete(iRotator);
	iRotator=NULL;
	}

//////////////////////////////////////////////////////////////////////////////////////////
CImageSaver::~CImageSaver()
	{
	Cancel();
	}

CImageSaver::CImageSaver(CImageDisplayControl& aDisplay) :
	CActive(CActive::EPriorityStandard),iDisplay(aDisplay)
	{
	// this cant leave so is totally reasonable to call within the constructor.
	CActiveScheduler::Add(this);
	}

void CImageSaver::StartSaveImageL(
//
// Start saving the image to the indicated file.
//
	const TFileName& aFileName,
	const TUid& aImageType,
	const TUid& aImageSubType,
	CFbsBitmap* aBitmap)
	{
	iSaver=CImageEncoder::FileNewL(CEikonEnv::Static()->FsSession(),aFileName,
										CImageEncoder::EOptionNone,aImageType,aImageSubType);

	// start saving the image into our bitmap. RunL() called when complete
	iSaver->Convert(&iStatus,*aBitmap);
	SetActive();
	}

void CImageSaver::RunL()
// The save operation has completed, sucessfully or otherwise. 
	{
	iDisplay.SaveComplete(iStatus.Int());
	delete(iSaver);
	iSaver=NULL;
	}

void CImageSaver::DoCancel()
// Cancel the image saving. By defn is called when we are IsActive().
	{
	iSaver->Cancel();
	delete(iSaver);
	iSaver=NULL;
	}

//////////////////////////////////////////////////////////////////////////////////////////
class CImageSaverDialog : public CEikDialog
	{
protected:
	// from CEikDialog
	void PreLayoutDynInitL();
	void HandleControlStateChangeL(TInt aControlId);
	TBool OkToExitL(TInt aButtonId);

	// new methods
	void SetImageSubTypesL();
public:
	// new methods
	~CImageSaverDialog();
	CImageSaverDialog(TDes& aName,TUid& aType,TUid& aSubType);

protected:
	TDes& iName;
	TUid& iType;
	TUid& iSubType;

	RImageTypeDescriptionArray iImageTypes;
	RImageTypeDescriptionArray iImageSubTypes;
	};

CImageSaverDialog::~CImageSaverDialog()
	{
	iImageSubTypes.ResetAndDestroy();
	iImageSubTypes.Close();
	iImageTypes.ResetAndDestroy();
	iImageTypes.Close();
	}

CImageSaverDialog::CImageSaverDialog(TDes& aName,TUid& aType,TUid& aSubType) :
	iName(aName),iType(aType),iSubType(aSubType)
	{}

void CImageSaverDialog::SetImageSubTypesL()
//
// Create the list of sub-types based on currently chosen primary type
//
	{
	// determine primary file type being manipulated
	CEikChoiceList* cl=static_cast<CEikChoiceList*>(Control(2));
	TUid type=iImageTypes[cl->CurrentItem()]->ImageType();

	// create the sub-types list based on primary type
	cl=static_cast<CEikChoiceList*>(Control(3)); 
	TRAPD(err,
		CImageEncoder::GetImageSubTypesL(type,iImageSubTypes)
		);
	if (err==KErrNotFound) // no sub-types reported via an error...
		{
		cl->SetArrayL(R_IMAGE_SAVE_NO_SUB_TYPES_ARRAY);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -