hi everyone!
I am displaying scaled jpeg images on a grid list. If a user select a particular image, that image will be saved as c:\\system\\apps\\appname\\appname.jpg. At first, i tried saving the scaled image, no problem here.
But what i want to do is save the image that has not been scaled down. I declared a temporary CFbsBitmap variable iBitmapDup, this is used for copying the original sized image. When i try to save a particular image, the image saved is always the last image on the grid (even if i select the first image on the grid). Why is this so? How can this problem be solved? Please help. Below are some snippets of the code. (I have also uploaded my source code in http://www.crystalwalkway.com/SimpleGrid.zip. Please save the images from the bitmaps folder to c:\\Nokia\\Images)
code for calling iConverter->OpenL()
code when opening image is finished. Image will then be converted to bitmap.Code:void CSimpleGridContainer::ListFiles() { ... if(dirList->Count() > 0 && iBitmapCounter == 0) { iBitmapCounter = dirList->Count(); iBitmapArray = RPointerArray<CFbsBitmap>(iBitmapCounter); } // // Process each entry // if(iBitmapCounter > 0 && iBitmapCounter > iBitmapOffset + 1) { iBitmapOffset++; fileName = (*dirList)[iBitmapOffset].iName; totalPath = KDirectory; totalPath.Append(fileName); //path of the jpeg image // You can add your processing here iBitmapTemp = new (ELeave) CFbsBitmap(); if(iScaler) { delete iScaler; iScaler = NULL; } iScaler = CMdaBitmapScaler::NewL(); if(iConverter) { delete iConverter; iConverter = NULL; } iConverter = CMdaImageFileToBitmapUtility::NewL(*this); iConverter->OpenL(totalPath); //open the image } ... }
code when conversion has finished. Something wrong here?Code:void CSimpleGridContainer::MiuoOpenComplete(TInt aError) { if(aError == KErrNone) { iConvertState = EConvertStateConvertingFromJpeg; TFrameInfo frameInfo; iConverter->FrameInfo(0, frameInfo); TInt err = iBitmapTemp->Create(frameInfo.iOverallSizeInPixels,KDeviceColourDepth); if (err == KErrCouldNotConnect) { //Could not connect to font and bitmap server return; } if (err == KErrArgument) { //Illegal jpeg file size return; } TRAPD(convertErr, iConverter->ConvertL(*iBitmapTemp,0)); if (convertErr != KErrNone) { //Cannot initiate converter } } }
Code for calling iFileSaver->ConvertL().Code:void CSimpleGridContainer::MiuoConvertComplete(TInt aError) { switch (iConvertState) { //Finished converting gif file to bitmap case EConvertStateConvertingFromJpeg: { //create a duplicate of iBitmapTemp so that the jpeg to be saved is of original size TBuf8<352> iBuf; TPoint point(0,0); TInt height = iBitmapTemp->SizeInPixels().iHeight; TInt width = iBitmapTemp->SizeInPixels().iWidth; TDisplayMode dMode = iBitmapTemp->DisplayMode(); if(iBitmapDup) { delete iBitmapDup; iBitmapDup = NULL; } iBitmapDup = new (ELeave) CFbsBitmap; iBitmapDup->Create(iBitmapTemp->SizeInPixels(), dMode); //copy iBitmapTemp to get original sized image for (TInt i = 0;i < height ; ++i) { point.iY=i; iBitmapTemp->GetScanLine(iBuf,point,width,dMode); iBitmapDup->SetScanLine(iBuf,i); } iBitmapArray.Append(iBitmapDup); ConvertingFromJpegFinished(aError); } break; //Finished Scaling file case EConvertStateScaling: ScalingFinished(aError); break; case EConvertStateSaving: SavingFinished(aError); break; case EConvertStateNull: default: ASSERT(FALSE); } }
Code for scaling jpeg.Code:void CSimpleGridContainer::MiuoCreateComplete(TInt aError) { if ((aError == KErrNone) && iFileSaver) { //Now the bitmap file has been created, write the bitmap to it TRAPD(err,iFileSaver->ConvertL(*(iBitmapArray[iSelected])) ); if (err != KErrNone) { //Conversion could not be started } } }
Code called when scaling finished.Code:void CSimpleGridContainer::ConvertingFromJpegFinished(TInt aError) { if (aError == KErrNone) { TRAPD(err,iScaler->ScaleL(*this,*iBitmapTemp,TSize(KNewImageWidth,KNewImageHeight))); if (err == KErrNone) { iConvertState = EConvertStateScaling; } } }
Code:void CSimpleGridContainer::ScalingFinished(TInt aError) { if (aError == KErrNone) { iConvertState = EConvertStateReady; LoadGraphicsL(); AddDataL(1); if(iBitmapCounter > iBitmapOffset + 1) { ListFiles(); } } }


Reply With Quote

