×
Namespaces

Variants
Actions

Display image gallery grid with asynchronous thumbnails 2nd Edition

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: rathodavinash (28 Jun 2007)
Last edited: hamishwillee (20 Jul 2012)

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.

This page was last modified on 20 July 2012, at 10:22.
60 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×