ImageConv
: Image Converter Library example
code
ImageConv
demonstrates the Image Converter Library API. It
shows how to:
read standard graphics formats (such as .bmp
or
.gif
) into CFbsBitmap
objects, from where they can be
manipulated and rendered to the screen
save CFbsBitmap
objects as files, using a number of
formats
rotate, flip, and zoom images
The Image Converter API is called by an engine class
CImageHandler
. The UI class, CImageAppUi
, supplies a
dialog that allows the user to choose a particular frame from a multi-frame
image (such as an animated .gif), and a dialog that allows the user to save the
current image in a particular format.
The source code for this example application can be found in the directory:
examples\MultiMedia\ImageConv\
Note: This code is designed to work only with Techview and is not guaranteed to work with other interfaces
These are the main files contained in the examples. Some extra files may be needed to run the examples, and these will be found in the appropriate examples directory.
//
// CImageApp.cpp
//
// Copyright (c) 2001-2005 Symbian Software Ltd. All rights reserved.
//
#include "CImageApp.h"
#include "CImageDocument.h"
#include <eikstart.h>
const TUid KUidImageConv = { 0x101F4113 };
TUid CImageApp::AppDllUid() const
{
return KUidImageConv;
}
CApaDocument* CImageApp::CreateDocumentL()
{
return new(ELeave) CImageDocument(*this);
}
//
// Exported function
//
EXPORT_C CApaApplication* NewApplication()
{
return new CImageApp;
}
GLDEF_C TInt E32Main()
{
return EikStart::RunApplication(NewApplication);
}
//
// CImageAppUi.cpp
//
// Copyright (c) 2001-2005 Symbian Software Ltd. All rights reserved.
#include <eikenv.h>
#include <Eikfile.rsg>
#include <eikmenub.h>
#include <eiklabel.h>
#include <imageconv.rsg>
#include "imageconv.hrh"
#include "CImageAppUi.h"
#include "CImageAppView.h"
_LIT(KCancelled, "Cancelled");
_LIT(KLoading,"Loading...");
_LIT(KSaving,"Saving...");
_LIT(KCDrive,"c:\\");
_LIT(KSamplesDir,"c:\\samples\\");
void CImageAppUi::ConstructL()
{
CEikAppUi::ConstructL();
// Construct view
iAppView = new(ELeave) CImageAppView;
iAppView->ConstructL(ClientRect());
AddToStackL(iAppView);
// Bitmap
iBitmap = new(ELeave) CFbsBitmap();
iBitmap->Create(TSize(0,0), EColor256);
iAppView->SetBitmap(iBitmap);
// Image handler
iImageHandler = new (ELeave) CImageHandler(*iBitmap, iEikonEnv->FsSession(), *this);
iImageHandler->ConstructL();
// Show menu bar
iEikonEnv->AppUiFactory()->MenuBar()->TryDisplayMenuBarL();
}
CImageAppUi::~CImageAppUi()
{
delete iBitmap;
delete iImageHandler;
if (iAppView)
{
RemoveFromStack(iAppView);
delete iAppView;
}
}
// Handle key events
// ESCAPE cancels loading or saving
TKeyResponse CImageAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
{
TKeyResponse ret = EKeyWasConsumed;
switch (aKeyEvent.iCode)
{
case EKeyEscape:
iImageHandler->Cancel();
CEikonEnv::Static()->BusyMsgCancel();
CEikonEnv::Static()->InfoMsg(KCancelled);
break;
default:
ret = EKeyWasNotConsumed;
break;
}
return ret;
}
// Handle commands
void CImageAppUi::HandleCommandL(TInt aCommand)
{
switch (aCommand)
{
// File | Open
case EImageCmdOpenFile:
OpenFileL();
break;
// File | Save As
case EImageCmdSaveAs:
SaveAsL();
break;
// Image | Zoom in
case EImageCmdZoomIn:
iImageHandler->ZoomFrame(ETrue);
break;
// Image | Zoom out
case EImageCmdZoomOut:
iImageHandler->ZoomFrame(EFalse);
break;
// Image | Rotate clockwise
case EImageCmdRotateClockwise:
iImageHandler->FrameRotate(ETrue);
break;
// Image | Rotate anti-clockwise
case EImageCmdRotateAntiClockwise:
iImageHandler->FrameRotate(EFalse);
break;
// Image | Mirror
case EImageCmdMirror:
iImageHandler->Mirror();
break;
// Image | Flip
case EImageCmdFlip:
iImageHandler->Flip();
break;
// Image | Refresh
case EImageCmdRefresh:
iImageHandler->LoadFileL(iLoadFileName);
break;
// Image | Select frame
case EImageCmdExtractFrame:
ExtractFrameL();
break;
// File | Close
case EEikCmdExit:
Exit();
break;
}
}
// Dim out image menu until image loaded
void CImageAppUi::DynInitMenuBarL(TInt /*aResourceId*/, CEikMenuBar* aMenuBar)
{
if (iBitmap->SizeInPixels().iWidth == 0)
{
// Get title index for Image menu pane
const CEikMenuBar::CTitleArray& titles = *(aMenuBar->MenuTitleArray());
for (TInt i=0; i < titles.Count(); i++)
if (titles[i]->iData.iMenuPaneResourceId == R_IMAGE_VIEW_MENU)
{
aMenuBar->SetTitleDimmed(i, ETrue);
break;
}
}
}
// Open File dialog
void CImageAppUi::OpenFileL()
{
if (iLoadFileName.Length() < 4)
iLoadFileName = KSamplesDir;
// Select a file
CEikDialog* dialog = new(ELeave) CEikFileOpenDialog(&iLoadFileName);
if (!dialog->ExecuteLD(R_EIK_DIALOG_FILE_OPEN)) return;
CEikonEnv::Static()->BusyMsgL(KLoading);
// Load the selected image file
iImageHandler->LoadFileL(iLoadFileName, 0);
}
// Select frame dialog
void CImageAppUi::ExtractFrameL()
{
// Get number of frames
TInt frameCount = iImageHandler->FrameCount();
// Select a frame
TInt selectedFrame = 0;
CEikDialog* dialog = new(ELeave) CImageCurrentFrameDialog(selectedFrame, frameCount);
if (!dialog->ExecuteLD(R_IMAGE_FRAME_DIALOG)) return;
CEikonEnv::Static()->BusyMsgL(KLoading);
// Load the selected frame
iImageHandler->LoadFileL(iLoadFileName, selectedFrame);
}
// Save as... dialog
void CImageAppUi::SaveAsL()
{
// Do the dialog
if (iSaveFileName.Length() < 4)
iSaveFileName = KCDrive;
CEikDialog* dialog = new(ELeave) CImageSaveAsDialog(&iSaveFileName, iSaveInfo);
if (!dialog->ExecuteLD(R_IMAGE_FILE_SAVEAS_DIALOG)) return;
CEikonEnv::Static()->BusyMsgL(KSaving);
// Save the image
iImageHandler->SaveFileL(iSaveFileName, iSaveInfo.iImageType, iSaveInfo.iImageSubType );
}
// Image operation complete callback
// Leaves will be caught by CONE error handling
void CImageAppUi::ImageOperationComplete(TInt aError)
{
CEikonEnv::Static()->BusyMsgCancel();
User::LeaveIfError(aError);
iAppView->Clear();
iAppView->DrawBitmapNow();
}
//
// CImageCurrentFrameDialog: select frame dialog
//
CImageCurrentFrameDialog::CImageCurrentFrameDialog(TInt& aCurrentFrame,TInt aNumberOfFrames):
iCurrentFrame(aCurrentFrame),
iNumberOfFrames(aNumberOfFrames)
{}
// Initialise dialog with current settings
void CImageCurrentFrameDialog::PreLayoutDynInitL()
{
CEikNumberEditor* frames = static_cast<CEikNumberEditor*>(Control(EImageIdNumberOfFrames));
frames -> SetNumber(0);
frames -> SetMinimumAndMaximum(0,iNumberOfFrames - 1);
}
// Store dialog result
TBool CImageCurrentFrameDialog::OkToExitL(TInt /*aButtonId*/)
{
CEikNumberEditor* frames = static_cast<CEikNumberEditor*>(Control(EImageIdNumberOfFrames));
iCurrentFrame = frames -> Number();
return ETrue;
}
//
// CImageSaveAsDialog: save as dialog
//
CImageSaveAsDialog::CImageSaveAsDialog(TDes* aFileName, TFileSaveDialogOptions& aSaveInfo):
CEikFileSaveAsDialog(aFileName),
iSaveInfo(aSaveInfo)
{}
// Set dialog with image types
void CImageSaveAsDialog::PreLayoutDynInitL()
{
CImageEncoder::GetImageTypesL(iImageTypes);
CEikChoiceList* types = static_cast<CEikChoiceList*>(Control(EImageIdSaveAsFormat));
CDesC16ArrayFlat* listItems = new (ELeave) CDesC16ArrayFlat(4);
for (int i=0; i<iImageTypes.Count(); i++)
listItems->AppendL(iImageTypes[i]->Description());
types->SetArrayL(listItems);
SetImageSubTypes();
CEikFileSaveAsDialog::PreLayoutDynInitL();
}
// Set image sub-types list
void CImageSaveAsDialog::SetImageSubTypes()
{
// Extract image format type chosen
CEikChoiceList* subtypes = static_cast<CEikChoiceList*>(Control(EImageIdSubtype));
CEikChoiceList* types = static_cast<CEikChoiceList*>(Control(EImageIdSaveAsFormat));
TUid type = iImageTypes[types->CurrentItem()]->ImageType(); // Image type
// Get list of available image sub-types
TRAPD(err, CImageEncoder::GetImageSubTypesL (type, iImageSubTypes));
if (err == KErrNotFound) // no sub-types
{
subtypes->SetArrayL(R_NO_SUB_TYPES);
subtypes->SetCurrentItem(0);
iSubtypeSet = EFalse;
return;
}
User::LeaveIfError(err); // leave for other errors
// Fill choicelist with sub-types
CDesC16ArrayFlat* listItems = new (ELeave) CDesC16ArrayFlat(4);
for (int i=0; i<iImageSubTypes.Count(); i++)
listItems->AppendL(iImageSubTypes[i]->Description());
subtypes->SetArrayL(listItems);
subtypes->SetCurrentItem(0);
iSubtypeSet = ETrue;
}
// Update any image sub-types
void CImageSaveAsDialog::HandleControlStateChangeL(TInt aControlId)
{
if (aControlId == EImageIdSaveAsFormat) SetImageSubTypes();
}
// Need to clean up RImageTypeDescriptionArray resources before exiting
CImageSaveAsDialog::~CImageSaveAsDialog()
{
iImageSubTypes.ResetAndDestroy();
iImageSubTypes.Close();
iImageTypes.ResetAndDestroy();
iImageTypes.Close();
}
// Store selected type
TBool CImageSaveAsDialog::OkToExitL(TInt aButtonId)
{
// Extract type chosen
CEikChoiceList* types = static_cast<CEikChoiceList*>(Control(EImageIdSaveAsFormat));
TInt index = types->CurrentItem();
iSaveInfo.iImageType = iImageTypes[index]->ImageType(); // Image type
if (iSubtypeSet)
{
CEikChoiceList* subtypes = static_cast<CEikChoiceList*>(Control(EImageIdSubtype));
iSaveInfo.iImageSubType = iImageSubTypes[subtypes->CurrentItem()]->SubType();// Image sub-type
}
else
iSaveInfo.iImageSubType = KNullUid;
return CEikFileSaveAsDialog::OkToExitL(aButtonId);
}
//
// CImageAppView.cpp
//
// Copyright (c) 2001-2005 Symbian Software Ltd. All rights reserved.
#include "CImageAppView.h"
// Construct empty window
void CImageAppView::ConstructL(const TRect& /*aRect*/)
{
CreateWindowL();
#if defined(__WINS__)
Window().SetRequiredDisplayMode(EColor256);
#endif
Window().SetBackgroundColor(KRgbDarkBlue);
SetExtentToWholeScreen();
ActivateL();
}
// Get display mode
TDisplayMode CImageAppView::DisplayMode() const
{
return Window().DisplayMode();
}
// Draw view
void CImageAppView::Draw(const TRect& /*aRect*/) const
{
CWindowGc& gc = SystemGc();
if (iBitmap && iBitmap->Handle())
{
TSize bitmapSize(iBitmap->SizeInPixels());
TPoint pt;
pt.iX = (Rect().Width() - bitmapSize.iWidth) / 2;
pt.iY = (Rect().Height() - bitmapSize.iHeight) / 2;
gc.BitBlt(pt,iBitmap);
}
else
gc.Clear();
}
// Draw view on demand
void CImageAppView::DrawBitmapNow()
{
CWindowGc& gc = SystemGc();
gc.Activate(Window());
Draw(Rect());
gc.Deactivate();
ControlEnv()->WsSession().Flush();
}
// Clear view
void CImageAppView::Clear()
{
CWindowGc& gc = SystemGc();
gc.Activate(Window());
gc.Clear();
gc.Deactivate();
ControlEnv()->WsSession().Flush();
}
// Set bitmap to draw
void CImageAppView::SetBitmap(CFbsBitmap* aBitmap)
{
iBitmap = aBitmap;
}
//
// CImageDocument.cpp
//
#include "CImageDocument.h"
#include "CImageAppUi.h"
CImageDocument::CImageDocument(CEikApplication& aApp)
: CEikDocument(aApp)
{
}
CEikAppUi* CImageDocument::CreateAppUiL()
{
return new(ELeave) CImageAppUi;
}
// Copyright (c) 2001-2005 Symbian Software Ltd. All rights reserved.
#include "CImageHandler.h"
CImageHandler::CImageHandler(CFbsBitmap& aBitmap, RFs& aFs, MImageHandlerCallback& aCallback)
: CActive(CActive::EPriorityStandard), iBitmap(aBitmap), iFs(aFs), iCallback(aCallback)
{}
void CImageHandler::ConstructL()
{
iBitmapRotator = CBitmapRotator::NewL();
iBitmapScaler = CBitmapScaler::NewL();
CActiveScheduler::Add(this);
}
CImageHandler::~CImageHandler()
{
delete iLoadUtil;
delete iSaveUtil;
delete iBitmapRotator;
delete iBitmapScaler;
}
void CImageHandler::LoadFileL(const TFileName& aFileName, TInt aSelectedFrame)
{
__ASSERT_ALWAYS(!IsActive(),User::Invariant());
// create a CImageDecoder to read the specified file
delete iLoadUtil;
iLoadUtil = NULL;
iLoadUtil = CImageDecoder::FileNewL(iFs, aFileName);
// store the frame information and frame count
iFrameInfo = iLoadUtil->FrameInfo(aSelectedFrame);
iFrameCount = iLoadUtil->FrameCount();
// resize the destination bitmap to fit the required size
TRect bitmapSize = iFrameInfo.iFrameCoordsInPixels;
iBitmap.Resize(bitmapSize.Size());
// start reading the bitmap: RunL called when complete
iLoadUtil->Convert(&iStatus, iBitmap, aSelectedFrame);
SetActive();
}
void CImageHandler::SaveFileL(const TFileName& aFileName, const TUid& aImageType, const TUid& aImageSubType)
{
__ASSERT_ALWAYS(!IsActive(),User::Invariant());
// create a CImageEncoder to save the bitmap to the specified file in the specified format
delete iSaveUtil;
iSaveUtil = NULL;
iSaveUtil = CImageEncoder::FileNewL(iFs, aFileName, CImageEncoder::EOptionNone, aImageType, aImageSubType);
// start saving the bitmap: RunL called when complete
iSaveUtil->Convert(&iStatus, iBitmap);
SetActive();
}
void CImageHandler::Mirror()
{
__ASSERT_ALWAYS(!IsActive(),User::Invariant());
// start rotating the bitmap: RunL called when complete
iBitmapRotator->Rotate(&iStatus, iBitmap, CBitmapRotator::EMirrorVerticalAxis);
SetActive();
}
void CImageHandler::Flip()
{
__ASSERT_ALWAYS(!IsActive(),User::Invariant());
// start rotating the bitmap: RunL called when complete
iBitmapRotator->Rotate(&iStatus, iBitmap, CBitmapRotator::EMirrorHorizontalAxis);
SetActive();
}
void CImageHandler::FrameRotate(TBool aClockwise)
{
__ASSERT_ALWAYS(!IsActive(),User::Invariant());
// start rotating the bitmap: RunL called when complete
if (aClockwise)
iBitmapRotator->Rotate(&iStatus, iBitmap, CBitmapRotator::ERotation90DegreesClockwise);
else
iBitmapRotator->Rotate(&iStatus, iBitmap, CBitmapRotator::ERotation270DegreesClockwise);
SetActive();
}
void CImageHandler::ZoomFrame(TBool aZoomIn)
{
__ASSERT_ALWAYS(!IsActive(),User::Invariant());
// Determine target zooming size
TSize size(iBitmap.SizeInPixels());
const TSize adjust(size.iWidth/2, size.iHeight/2);
if (aZoomIn)
size += adjust;
else
size -= adjust;
// Don't let it go too small
if (size.iWidth <= 10) size.iWidth = 10;
if (size.iHeight <= 10) size.iHeight = 10;
// start scaling the bitmap: RunL called when complete
iBitmapScaler->Scale(&iStatus, iBitmap, size);
SetActive();
}
void CImageHandler::RunL()
{
// Operation complete, call back caller
iCallback.ImageOperationComplete(iStatus.Int());
}
void CImageHandler::DoCancel()
{
// Cancel everything possible
if (iLoadUtil) iLoadUtil->Cancel();
if (iSaveUtil) iSaveUtil->Cancel();
iBitmapRotator->Cancel();
iBitmapScaler->Cancel();
}
// CImageApp.h
//
// Copyright (c) 2001 Symbian Ltd. All rights reserved.
//
#ifndef CIMAGEAPP
#define CIMAGEAPP
#include <eikapp.h>
class CImageApp : public CEikApplication
{
private:
// from CApaApplication
CApaDocument* CreateDocumentL();
TUid AppDllUid() const;
};
#endif // CIMAGEAPP
//
// CImageAppUi.h
//
// Copyright (c) 2001-2005 Symbian Software Ltd. All rights reserved.
//
#ifndef CIMAGEAPPUI
#define CIMAGEAPPUI
#include <fbs.h>
#include <eikappui.h>
#include <eikdialg.h>
#include <eikcfdlg.h>
#include <eikchlst.h>
#include <eikmfne.h>
#include "CImageHandler.h"
// TFileSaveDialogOptions
// Options that specify how an image should be saved
class TFileSaveDialogOptions
{
public:
TUid iImageType; // Image type
TUid iImageSubType; // Image sub-type
};
class CImageAppView;
// CImageAppUi
// Handles commands, and invokes ICL functions appropriately
class CImageAppUi : public CEikAppUi, public MImageHandlerCallback
{
public:
void ConstructL();
~CImageAppUi();
private:
// Image operation complete, so need to refresh view
void ImageOperationComplete(TInt aError);
// From CCoeAppUi
TKeyResponse HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
// From CEikAppUi
void HandleCommandL(TInt aCommand);
void DynInitMenuBarL(TInt aResourceId, CEikMenuBar* aMenuBar);
// File command handling functions
void OpenFileL();
void SaveAsL();
void ExtractFrameL();
private:
CImageHandler* iImageHandler;
CImageAppView* iAppView; // App view
CFbsBitmap* iBitmap; // Bitmap
TFileName iLoadFileName; // File name to load
TFileName iSaveFileName; // File name to save
TFileSaveDialogOptions iSaveInfo; // Save options
};
// CImageCurrentFrameDialog
// Selects frame to extract
class CImageCurrentFrameDialog : public CEikDialog
{
public:
CImageCurrentFrameDialog(TInt& aCurrentFrame,TInt aNumberOfFrames);
protected:
// From CEikDialog
virtual void PreLayoutDynInitL();
virtual TBool OkToExitL(TInt aButtonId);
private:
TInt& iCurrentFrame;
TInt iNumberOfFrames;
};
// CImageSaveAsDialog
// Save As dialog
class CImageSaveAsDialog : public CEikFileSaveAsDialog
{
public:
CImageSaveAsDialog(TDes* aFileName, TFileSaveDialogOptions& aSaveInfo);
~CImageSaveAsDialog();
private:
// from CEikDialog
void PreLayoutDynInitL();
TBool OkToExitL(TInt aButtonId);
void HandleControlStateChangeL(TInt aControlId);
void SetImageSubTypes();
private:
// dialog settings returned
TFileSaveDialogOptions& iSaveInfo;
// stores dynamic list of image types available
RImageTypeDescriptionArray iImageTypes;
// stores dynamic list of image subtypes available
RImageTypeDescriptionArray iImageSubTypes;
// flag set if sub-type set
TBool iSubtypeSet;
};
#endif //CIMAGEAPPUI
// CImageAppView.H
//
// Copyright (c) 2001 Symbian Ltd. All rights reserved.
//
#ifndef CIMAGEAPPVIEW
#define CIMAGEAPPVIEW
#include <coecntrl.h>
#include <fbs.h>
#include "CImageAppUi.h"
// Application view: displays the bitmap
class CImageAppView : public CCoeControl, public MCoeControlBrushContext
{
public:
void ConstructL(const TRect& aRect);
// Get display mode
TDisplayMode DisplayMode() const;
// Draw view
void DrawBitmapNow();
// Clear view
void Clear();
// Set bitmap to draw
void SetBitmap(CFbsBitmap* aBitmap);
private:
// from CCoeControl
void Draw(const TRect& /*aRect*/) const;
private:
CFbsBitmap* iBitmap;
};
#endif
// CImageDocument.h
//
// Copyright (c) 2001-2005 Symbian Software Ltd. All rights reserved.
//
#ifndef CIMAGEDOCUMENT
#define CIMAGEDOCUMENT
#include <eikdoc.h>
class CImageDocument : public CEikDocument
{
public:
CImageDocument(CEikApplication& aApp);
private:
// from CEikDocument
CEikAppUi* CreateAppUiL();
};
#endif
// CImageAppView.H
//
// Copyright (c) 2002-2005 Symbian Software Ltd. All rights reserved.
//
#ifndef CIMAGEHANDLER_H
#define CIMAGEHANDLER_H
#include <e32base.h>
#include <fbs.h>
// Image converter library API header
#include <ImageConversion.h>
// Bitmap transforms API header
#include <BitmapTransforms.h>
// Callback from image handler
class MImageHandlerCallback
{
public:
// Handler calls when image manipulation is completed
virtual void ImageOperationComplete(TInt aError) = 0;
};
// Loads, saves and manipulates a bitmap
class CImageHandler : public CActive
{
public:
// Construction
CImageHandler(CFbsBitmap& aBitmap, RFs& aFs, MImageHandlerCallback& aCallback);
void ConstructL();
~CImageHandler();
// Load/save operations
void LoadFileL(const TFileName& aFileName, TInt aSelectedFrame = 0);
void SaveFileL(const TFileName& aFileName, const TUid& aImageType, const TUid& aImageSubType);
// Image command handling functions
void FrameRotate(TBool aClockwise);
void Mirror();
void Flip();
void ZoomFrame(TBool aZoomIn);
// Frame information
const TFrameInfo& FrameInfo() const {return iFrameInfo;}
// Frame count
TInt FrameCount() const {return iFrameCount;}
private:
// Active object interface
void RunL();
void DoCancel();
private:
// Bitmap
CFbsBitmap& iBitmap;
// File server handle
RFs& iFs;
// Callback interface
MImageHandlerCallback& iCallback;
// Frame information
TFrameInfo iFrameInfo;
// Frame count
TInt iFrameCount;
// Image file loader
CImageDecoder* iLoadUtil;
// Image files saver
CImageEncoder* iSaveUtil;
// Bitmap rotator
CBitmapRotator* iBitmapRotator;
// Bitmap zoomer
CBitmapScaler* iBitmapScaler;
};
#endif
// Imageconv.HRH
//
// Copyright (c) 2001-2005 Symbian Software Ltd. All rights reserved.
//
// Commands
enum
{
EImageCmdOpenFile=1,
EImageCmdSaveAs,
EImageCmdZoomIn,
EImageCmdZoomOut,
EImageCmdMirror,
EImageCmdFlip,
EImageCmdStream,
EImageCmdRefresh,
EImageCmdExtractFrame,
EImageCmdRotateClockwise,
EImageCmdRotateAntiClockwise
};
enum
{
EImageIdNumberOfFrames=1,
EImageIdDisplayMode,
EImageIdBackgroundColor,
EImageIdCurrentFrameNumber
};
enum
{
EImageIdSaveAsFormat=1000, // Avoid clashes with the existing Save As dialog controls
EImageIdSubtype
};
enum
{
EImageBidFormat=1000 // Avoid clashes with the existing Save As dialog buttons
};
enum
{
EImageIdFileFormatType=1,
EImageIdFileFormatBpp,
EImageIdFileFormatColor,
EImageIdFileFormatFactor,
EImageIdFileFormatSampling
};
/ Imageconv.HRH
//
// Copyright (c) 2001-2005 Symbian Software Ltd. All rights reserved.
//
// Commands
enum
{
EImageCmdOpenFile=1,
EImageCmdSaveAs,
EImageCmdZoomIn,
EImageCmdZoomOut,
EImageCmdMirror,
EImageCmdFlip,
EImageCmdStream,
EImageCmdRefresh,
EImageCmdExtractFrame,
EImageCmdRotateClockwise,
EImageCmdRotateAntiClockwise
};
enum
{
EImageIdNumberOfFrames=1,
EImageIdDisplayMode,
EImageIdBackgroundColor,
EImageIdCurrentFrameNumber
};
enum
{
EImageIdSaveAsFormat=1000, // Avoid clashes with the existing Save As dialog controls
EImageIdSubtype
};
enum
{
EImageBidFormat=1000 // Avoid clashes with the existing Save As dialog buttons
};
enum
{
EImageIdFileFormatType=1,
EImageIdFileFormatBpp,
EImageIdFileFormatColor,
EImageIdFileFormatFactor,
EImageIdFileFormatSampling
};
// ImageConv.RSS
//
// Copyright (c) 2001-2005 Symbian Software Ltd. All rights reserved.
//
NAME IMGC
#include <eikon.rh>
#include <eikon.rsg>
#include "imageconv.hrh"
RESOURCE RSS_SIGNATURE { }
RESOURCE TBUF { buf=""; }
// App UI
RESOURCE EIK_APP_INFO
{
menubar=r_image_menubar;
hotkeys=r_image_hotkeys;
}
// Command hotkeys
RESOURCE HOTKEYS r_image_hotkeys
{
control=
{
HOTKEY { command=EImageCmdSaveAs; key='a'; },
HOTKEY { command=EEikCmdExit; key='e'; },
HOTKEY { command=EImageCmdExtractFrame; key='f'; },
HOTKEY { command=EImageCmdZoomIn; key='m'; },
HOTKEY { command=EImageCmdOpenFile; key='o'; },
HOTKEY { command=EImageCmdRotateClockwise; key='q'; },
HOTKEY { command=EImageCmdRefresh; key='r'; }
};
shift_control=
{
HOTKEY { command=EImageCmdZoomOut; key='m'; },
HOTKEY { command=EImageCmdRotateAntiClockwise; key='q'; }
};
}
// Menu bar
RESOURCE MENU_BAR r_image_menubar
{
titles=
{
MENU_TITLE { menu_pane=r_image_file_menu; txt="File"; },
MENU_TITLE { menu_pane=r_image_view_menu; txt="Image"; }
};
}
// File menu
RESOURCE MENU_PANE r_image_file_menu
{
items=
{
MENU_ITEM { command=EImageCmdOpenFile; txt="Open file"<KEllipsis>; },
MENU_ITEM { command=EImageCmdSaveAs; txt="Save as"<KEllipsis>; flags=EEikMenuItemSeparatorAfter; },
MENU_ITEM { command=EEikCmdExit; txt="Close"; }
};
}
// Image menu
RESOURCE MENU_PANE r_image_view_menu
{
items=
{
MENU_ITEM { command=EImageCmdZoomIn; txt="Zoom in"; },
MENU_ITEM { command=EImageCmdZoomOut; txt="Zoom out"; },
MENU_ITEM { command=EImageCmdRotateClockwise; txt="Rotate clockwise"; },
MENU_ITEM { command=EImageCmdRotateAntiClockwise; txt="Rotate anti-clockwise"; },
MENU_ITEM { command=EImageCmdMirror; txt="Mirror"; },
MENU_ITEM { command=EImageCmdFlip; txt="Flip"; },
MENU_ITEM { command=EImageCmdRefresh; txt="Refresh"; },
MENU_ITEM { command=EImageCmdExtractFrame; txt="Select frame"<KEllipsis>; }
};
}
// Frame selection dialog
RESOURCE DIALOG r_image_frame_dialog
{
title="Set current frame";
flags=EEikDialogFlagWait;
buttons=R_EIK_BUTTONS_CANCEL_OK;
items=
{
DLG_LINE
{
prompt="Frame number:";
type=EEikCtNumberEditor;
id=EImageIdNumberOfFrames;
control=NUMBER_EDITOR
{
min=0;
max=999999;
};
}
};
}
// Save As dialog
RESOURCE DIALOG r_image_file_saveas_dialog
{
flags=EEikDialogFlagWait;
title="Save as";
buttons=r_image_browse_cancel_ok_buttons;
items=
{
DLG_LINE
{
prompt="Name";
type=EEikCtFileNameEd;
id=EEikCidFileNameEd;
control=FILENAMEEDITOR {};
},
DLG_LINE
{
prompt="Folder";
type=EEikCtFolderNameSel;
id=EEikCidFolderNameSel;
control=FOLDERNAMESELECTOR {};
},
DLG_LINE
{
prompt="Disk";
type=EEikCtDriveNameSel;
id=EEikCidDriveNameSel;
control=DRIVENAMESELECTOR {};
},
DLG_LINE
{
type=EEikCtCheckBox;
prompt="Use new file";
id=EEikCidUseNewFileChbx;
},
DLG_LINE
{
type=EEikCtChoiceList;
prompt="Type";
id=EImageIdSaveAsFormat;
control=CHOICELIST {};
},
DLG_LINE
{
type=EEikCtChoiceList;
prompt="Sub-type";
id=EImageIdSubtype;
control=CHOICELIST {};
}
};
}
// Set-format dialog buttons
RESOURCE DLG_BUTTONS r_image_browse_cancel_ok_buttons
{
buttons=
{
DLG_BUTTON { id=EEikBidBrowse; button=CMBUT {txt="Browse"<KEllipsis>;}; hotkey='B'; },
DLG_BUTTON { id=EEikBidCancel; button=CMBUT {txt="Cancel";}; hotkey=EEikBidCancel; flags=0;},
DLG_BUTTON { id=EEikBidOk; button=CMBUT {txt="OK";}; hotkey=EEikBidOk; flags=0; }
};
}
RESOURCE ARRAY r_no_sub_types
{
items=
{
LBUF { txt="None";}
};
}
ImageConv_reg.rss
#include <appinfo.rh>
UID2 KUidAppRegistrationResourceFile
UID3 0x101F4113 // application UID
RESOURCE APP_REGISTRATION_INFO
{
app_file = "ImageConv";
}
The source code for this example application can be found in the directory:
examples\MultiMedia\ImageConv\
It may be in the directory in which you installed Symbian OS, or it may
be in src\common\developerlibrary\
. It includes the two project
files needed for building: bld.inf
and the .mmp
file.
The Symbian OS build process describes how to build this application. For the emulator, an
application called ImageConv.exe
is created in
epoc32\release\winscw\<udeb or urel>\
.
Launch the emulator:
\epoc32\release\winscw\<urel or udeb>\EPOC.EXE
.
Click on IMAGECONV
to run the application. If
using the TechView emulator, this will be in the
Extras menu.
A collection of sample files of different formats is included. See
the readme.txt
in ImageConv\samples\
for notes on the
characteristics of each sample file.
Commands are given to the example through its
File
and Image
menus. The commands are:
Open file
: opens a graphics file and
converts it into a displayable CFbsBitmap
object
Save as
: saves the current bitmap
(CFbsBitmap
object) in a selectable format
Zoom in
and Zoom out
:
zooms the current image
Rotate clockwise
and Rotate
anti-clockwise
: rotates the current image
Mirror
produces a mirror image
Flip
turns the image upside-down
Refresh
: reloads the image from file
Select frame
: selects a frame from a
multi-frame image