Categories: Symbian C++ | How To | Code Examples | UI
Display image gallery grid with asynchronous thumbnails 2nd Edition
From Forum Nokia Wiki
S60 2nd Edition offers CPAlbImageFactory and CPAlbImageData classes to create thumbnails. Thumbnails can be created Synchronously or Asynchronously. This example demonstrates asynchronous method of getting thumbnails. For images which have high resolution the thumbnail creation takes a lot of time, hence user experience in showing the image gallery suffers. To show an image gallery in the grid format create a 3x3 grid which will hold the thumbnails of the images in the gallery. Create a default/loading image which will be shown if a thumbnail needs to be created. This is not required in case the thumbnail is already present for a particular image. This can be found with the function HasThumbnailL.
Keep a record of which grid cells need a thumbnail creation. Once we are through with all the photos in the gallery i.e. C:\Nokia\Images\*.jpg or E:\Images\*.jpg we can start creating asynchronous thumbnails of the files whose thumbnails were not already present.
This is done by
#ifdef __WINS__ imageData->SetSubFolderL(KNullDesC()); #else imageData->SetSubFolderL(KCDirName); #endif imageData->SetImageNameL(iFileName->MdcaPoint(iTNCounter)); iImageFactory->GetThumbnailAsync(*imageData);
The above code triggers the thumbnail creation process.
Remember that relevent data structures need to be created to remember which thumbnails are to be created.
We need to implement an observer class MPAlbImageFactoryObserver so that we get a notification when the thumbnail creation is over. Once the thumbnail is created the following function is called
void CMyContainer::MPTfoCreateComplete(CPAlbImageFactory* aObj,TInt aError,CFbsBitmap* aBitmap) { if(aError == KErrNone) { if(aBitmap!=NULL) { CGulIcon* icon = NULL; icon = CGulIcon::NewL(aBitmap, NULL); iGrid->ItemDrawer()->ColumnData()->IconArray()->AppendL(icon); MDesCArray* textArray = iGrid->Model()->ItemTextArray(); CDesCArray* itemList = static_cast<CDesCArray*>(textArray); itemList->Delete(iTNCounter); TBuf<128> buf; buf.Format(KFormatString,iGrid->ItemDrawer()->ColumnData()->IconArray()->Count()-1,iFileName->MdcaPoint(iTNCounter)); itemList->InsertL(iTNCounter,buf); iGrid->View()->DrawItem(iTNCounter); iTNArrPtr->AppendL(aObj); iImageFactory=NULL; } CreateTN(); //Keep creating unless over or user exits } } void CMobloggerGalContainer::CreateTN() { TBool iDone(EFalse); iTNCounter++; if(iTNCounter < iFiles->Count()) { TBool iTNExists; CPAlbImageFactory* iImageFactory1; iImageFactory1 = CPAlbImageFactory::NewL(this); CPAlbImageData* imageData1 = CPAlbImageData::NewL(); do { iTNExists=EFalse; imageData1->SetImageNameL(iFileName->MdcaPoint(iTNCounter)); #ifdef __WINS__ imageData1->SetSubFolderL(KNullDesC()); #else imageData1->SetSubFolderL(KCDirName); #endif if(iImageFactory1->HasThumbnailL(*imageData1)) { iTNExists=ETrue; iTNCounter++; if(!(iTNCounter < iSessionFiles->Count())) { iDone=ETrue; iTNExists=EFalse; iImageFactory=NULL; delete imageData1; } } else { iTNExists=EFalse; } }while(iTNExists); if(!iDone) { iImageFactory1->GetThumbnailAsync(*imageData1); iImageFactory=iImageFactory1; delete imageData1; } }//if icounter > 0 else { iImageFactory=NULL; } }
It can be seen that as the thumbnails are created the default image is deleted and the created thumbnail is inserted into the grid. Thus we have our own image gallery.
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to send MMS in 2nd edition? | yosr eman | Symbian Networking & Messaging | 6 | 2008-06-25 14:48 |
| I want to Display an image as part of installation | johnward1978 | General Symbian C++ | 1 | 2004-10-19 05:02 |
| what's the difference between all the follow versions? | zushuboderen | Symbian | 2 | 2007-04-23 04:17 |
| S60 2nd OR 3rd edition for new software development | patil_ruturaj | Symbian Tools & SDKs | 1 | 2006-06-30 10:30 |
| Carbide 1.3为什么找不到SDK? | ljyit | Symbian | 4 | 2008-03-30 11:18 |
