diff -r 89d6a7a84779 -r 25a17d01db0c Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/iclencodeexample_8cpp-source.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/iclencodeexample_8cpp-source.html Fri Jan 22 18:26:19 2010 +0000 @@ -0,0 +1,501 @@ + +
+00001 // iclencodeexample.cpp +00002 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +00003 // All rights reserved. +00004 // This component and the accompanying materials are made available +00005 // under the terms of "Eclipse Public License v1.0" +00006 // which accompanies this distribution, and is available +00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html". +00008 // +00009 // Initial Contributors: +00010 // Nokia Corporation - initial contribution. +00011 // +00012 // Contributors: +00013 // +00014 // Description: +00015 // +00016 // +00017 +00018 +00039 #include "iclexample.h" +00040 #include <gifscaler.h> +00041 #include <imagetransform.h> +00042 +00053 void CIclExample::EncodeBitmapToDescriptorL(const TDesC& aFileName) +00054 { +00055 HBufC8* encodedImageDescriptor = NULL; +00056 +00057 // Create the encoder, passing a buffer to store the encoded image +00058 CImageEncoder* encoder = CImageEncoder::DataNewL(encodedImageDescriptor, CImageEncoder::EOptionNone,KImageTypeGIFUid); +00059 CleanupStack::PushL(encoder); +00060 +00061 // Create a CFbsBitmap to store the source bitmap to encode +00062 CFbsBitmap* sourceBitmap = new(ELeave) CFbsBitmap; +00063 CleanupStack::PushL(sourceBitmap); +00064 +00065 User::LeaveIfError(sourceBitmap->Create(TSize(20,30), EColor16M)); +00066 User::LeaveIfError(sourceBitmap->Load(aFileName)); +00067 +00068 // See Note 1 +00069 CActiveListener* activeListener = CreateAndInitializeActiveListenerLC(); +00070 +00071 // Convert the image +00072 encoder->Convert(&activeListener->iStatus, *sourceBitmap); +00073 +00074 // See Note 2 +00075 CActiveScheduler::Start(); +00076 User::LeaveIfError(activeListener->iStatus.Int());// encode complete either display the image or report an error. +00077 +00078 +00079 CleanupStack::PopAndDestroy(3); // encoder, sourceBitmap and activeListener +00080 +00081 +00082 // We can use the descriptor here +00083 +00084 // And as we took ownership back, we need to push into the cleanup stack to make sure no +00085 // memory leaks take place if any leave later +00086 +00087 CleanupDeletePushL(encodedImageDescriptor); +00088 +00089 +00090 // Just verifying the presence of some output. +00091 +00092 RFile file; +00093 +00094 User::LeaveIfError(file.Replace(iFs, _L("c:\\ICLExample\\encodeddescriptor.mbm"), EFileWrite)); +00095 CleanupClosePushL(file); +00096 +00097 User::LeaveIfError(file.Write(*encodedImageDescriptor)); +00098 +00099 CleanupStack::PopAndDestroy(&file); +00100 +00101 +00102 CleanupStack::PopAndDestroy(encodedImageDescriptor); +00103 } +00104 +00105 +00116 void CIclExample::EncodeImageWithThumbnailL(const TDesC& aFileName) +00117 { +00118 HBufC8* encodedImageDescriptor = NULL; +00119 +00120 // Create the encoder, passing a buffer to store the encoded image +00121 CImageEncoder* encoder = CImageEncoder::DataNewL(encodedImageDescriptor, CImageEncoder::EOptionNone, KImageTypeJPGUid); +00122 CleanupStack::PushL(encoder); +00123 +00124 // Set the image type to thumbnail +00125 encoder->SetThumbnail(ETrue); +00126 +00127 // Create a bitmap to access the thumbnail +00128 CFbsBitmap* sourceBitmap = new(ELeave) CFbsBitmap; +00129 CleanupStack::PushL(sourceBitmap); +00130 +00131 User::LeaveIfError(sourceBitmap->Create(TSize(250,200), EColor16M)); +00132 User::LeaveIfError(sourceBitmap->Load(aFileName)); +00133 +00134 // See Note 1 +00135 CActiveListener* activeListener = CreateAndInitializeActiveListenerLC(); +00136 +00137 // Convert the image +00138 encoder->Convert(&activeListener->iStatus, *sourceBitmap); +00139 +00140 // See Note 2 +00141 CActiveScheduler::Start(); +00142 User::LeaveIfError(activeListener->iStatus.Int()); // access to thumbnail complete either display the image or report an error. +00143 +00144 +00145 CleanupStack::PopAndDestroy(3); // encoder, sourceBitmap and activeListener +00146 +00147 +00148 // We can use the descriptor here +00149 +00150 // And as we took ownership back, we need to push into the cleanup stack to make sure no +00151 // memory leaks take place if any leave later +00152 +00153 CleanupDeletePushL(encodedImageDescriptor); +00154 +00155 +00156 // Just verifying the presence of some output. +00157 +00158 RFile file; +00159 +00160 User::LeaveIfError(file.Replace(iFs, _L("c:\\ICLExample\\encodedbitmapwiththumbnail.mbm"), EFileWrite)); +00161 CleanupClosePushL(file); +00162 +00163 User::LeaveIfError(file.Write(*encodedImageDescriptor)); +00164 +00165 CleanupStack::PopAndDestroy(&file); +00166 +00167 +00168 CleanupStack::PopAndDestroy(encodedImageDescriptor); +00169 } +00170 +00171 +00183 void CIclExample::SettingExifMetadataL(const TDesC& aFileName) +00184 { +00185 HBufC8* encodedImageDescriptor = NULL; +00186 +00187 // Create the encoder, passing a buffer to store the encoded image +00188 CJPEGExifEncoder* exifEncoder = static_cast<CJPEGExifEncoder*>(CImageEncoder::DataNewL(encodedImageDescriptor, CImageEncoder::EOptionNone, KImageTypeJPGUid)); +00189 CleanupStack::PushL(exifEncoder); +00190 +00191 // Create a MExifMetadata object and initialize it with the metadata associated with CJPEGexifEncoder +00192 MExifMetadataWriter* metaData = exifEncoder->ExifMetadata(); +00193 +00194 // Create a TExifWriterUtility object to write the metadata in to the image +00195 TExifWriterUtility exifWriteUtility(metaData); +00196 +00197 HBufC8* buf8ParamWriteVersion = KBuf8ParamWriteVersion().AllocLC(); +00198 +00199 User::LeaveIfError(exifWriteUtility.SetImageDescription(buf8ParamWriteVersion)); +00200 +00201 CleanupStack::PopAndDestroy(buf8ParamWriteVersion); +00202 +00203 +00204 // Create a bitmap +00205 CFbsBitmap* sourceBitmap = new(ELeave) CFbsBitmap; +00206 CleanupStack::PushL(sourceBitmap); +00207 +00208 User::LeaveIfError(sourceBitmap->Create(TSize(250,200), EColor16M)); +00209 User::LeaveIfError(sourceBitmap->Load(aFileName)); +00210 +00211 // See Note 1 +00212 CActiveListener* activeListener = CreateAndInitializeActiveListenerLC(); +00213 +00214 // Convert the image +00215 exifEncoder->Convert(&activeListener->iStatus, *sourceBitmap); +00216 +00217 // See Note 2 +00218 CActiveScheduler::Start(); +00219 User::LeaveIfError(activeListener->iStatus.Int()); +00220 +00221 +00222 CleanupStack::PopAndDestroy(3); // encoder, sourceBitmap and activeListener +00223 +00224 +00225 // We can use the descriptor here +00226 +00227 // And as we took ownership back, we need to push into the cleanup stack to make sure no +00228 // memory leaks take place if any leave later +00229 +00230 CleanupDeletePushL(encodedImageDescriptor); +00231 +00232 +00233 // Just verifying the presence of some output. +00234 +00235 RFile file; +00236 +00237 User::LeaveIfError(file.Replace(iFs, _L("c:\\ICLExample\\settingexifdescriptor.mbm"), EFileWrite)); +00238 CleanupClosePushL(file); +00239 +00240 User::LeaveIfError(file.Write(*encodedImageDescriptor)); +00241 +00242 CleanupStack::PopAndDestroy(&file); +00243 +00244 +00245 CleanupStack::PopAndDestroy(encodedImageDescriptor); +00246 } +00247 +00248 +00256 void CIclExample::RotateBitmapL(const TDesC& aFileName) +00257 { +00258 // Create a CBitmapRotator object and push it on the cleanup stack +00259 CBitmapRotator* rotator = CBitmapRotator::NewL(); +00260 CleanupStack::PushL(rotator); +00261 +00262 // Create a source bitmap +00263 CFbsBitmap* sourceBitmap = new(ELeave) CFbsBitmap; +00264 CleanupStack::PushL(sourceBitmap); +00265 +00266 User::LeaveIfError(sourceBitmap->Create(TSize(15,20), EColor16M)); +00267 User::LeaveIfError(sourceBitmap->Load(aFileName)); +00268 +00269 // See Note 1 +00270 CActiveListener* activeListener = CreateAndInitializeActiveListenerLC(); +00271 +00272 // Rotate the bitmap through the specified angle +00273 rotator->Rotate(&activeListener->iStatus, *sourceBitmap, CBitmapRotator::ERotation180DegreesClockwise); +00274 +00275 // See Note 2 +00276 CActiveScheduler::Start(); +00277 User::LeaveIfError(activeListener->iStatus.Int()); +00278 +00279 // Just verifying the presence of some output. +00280 sourceBitmap->Save(_L("c:\\ICLExample\\rotatedbitmap.mbm")); +00281 +00282 +00283 CleanupStack::PopAndDestroy(3); // rotator, sourceBitmap and activeListener +00284 } +00285 +00286 +00295 void CIclExample::ScaleBitmapL(const TDesC& aFileName) +00296 { +00297 // Create a source bitmap object and push it on to the cleanup stack +00298 CFbsBitmap* sourceBitmap = new(ELeave) CFbsBitmap; +00299 CleanupStack::PushL(sourceBitmap); +00300 +00301 User::LeaveIfError(sourceBitmap->Create(TSize(100,100), EGray2)); +00302 User::LeaveIfError(sourceBitmap->Load(aFileName)); +00303 +00304 // Create a destination bitmap object and push it on to the cleanup stack +00305 CFbsBitmap* destBitmap = new(ELeave) CFbsBitmap; +00306 CleanupStack::PushL(destBitmap); +00307 +00308 User::LeaveIfError(destBitmap->Create(TSize(20,30), EColor16M)); +00309 +00310 // Scale the bitmap with old algorithm +00311 // Create a CBitmapScaler object and push it on to the cleanup stack +00312 CBitmapScaler* scaler = CBitmapScaler::NewL(); +00313 CleanupStack::PushL(scaler); +00314 +00315 // See Note 1 +00316 CActiveListener* activeListener = CreateAndInitializeActiveListenerLC(); +00317 +00318 // Scale the bitmap using low memory and medium quality algorithm +00319 scaler->UseLowMemoryAlgorithm(ETrue); +00320 scaler->SetQualityAlgorithm(CBitmapScaler::EMediumQuality); +00321 +00322 // Call the scale() function of CBitmapScaler to perform the scaling operation with optional selection of low memory +00323 scaler->Scale(&activeListener->iStatus, *sourceBitmap, *destBitmap, EFalse); +00324 +00325 // See Note 2 +00326 CActiveScheduler::Start(); +00327 User::LeaveIfError(activeListener->iStatus.Int());// scale complete either display the image or report an error. +00328 +00329 // Just verifying the presence of some output. Descriptor can also be used instead +00330 +00331 destBitmap->Save(_L("c:\\ICLExample\\scaledbitmap.mbm")); +00332 +00333 +00334 CleanupStack::PopAndDestroy(4); // activeListener, scaler, destBitmap and sourceBitmap +00335 } +00336 +00337 +00348 void CIclExample::SetSourceDestinationandResizeL(const TDesC& aFileName) +00349 { +00350 HBufC8* desData = NULL; +00351 +00352 // Create CImageTransform object and push it on to the cleanup stack +00353 CImageTransform* imageTransform = CImageTransform::NewL(iFs); +00354 CleanupStack::PushL(imageTransform); +00355 +00356 imageTransform->SetSourceFilenameL(aFileName); +00357 imageTransform->SetDestDataL(desData); +00358 imageTransform->SetDestSizeInPixelsL(TSize(160, 120), ETrue); +00359 imageTransform->SetupL(); +00360 +00361 // See Note 1 +00362 CActiveListener* activeListener = CreateAndInitializeActiveListenerLC(); +00363 +00364 // Call Transform() function of CImageTransform for image transform operation +00365 imageTransform->Transform(activeListener->iStatus); +00366 +00367 // See Note 2 +00368 CActiveScheduler::Start(); +00369 // destData ownership is on CLI side if something goes wrong +00370 User::LeaveIfError(activeListener->iStatus.Int()); +00371 +00372 +00373 CleanupStack::PopAndDestroy(2); // imageTransform and activeListener +00374 +00375 +00376 // We can use the destination data here +00377 +00378 // And as we took ownership back, we need to push into the cleanup stack to make sure no +00379 // memory leaks take place if any leave later +00380 +00381 CleanupDeletePushL(desData); +00382 +00383 +00384 // Just verifying the presence of some output. +00385 +00386 RFile file; +00387 +00388 User::LeaveIfError(file.Replace(iFs, _L("c:\\ICLExample\\destdata.mbm"), EFileWrite)); +00389 CleanupClosePushL(file); +00390 +00391 User::LeaveIfError(file.Write(*desData)); +00392 +00393 CleanupStack::PopAndDestroy(&file); +00394 +00395 +00396 CleanupStack::PopAndDestroy(desData); +00397 } +00398 +00399 +00412 void CIclExample::SettingWithUseOfPreserveImageDataL(const TDesC& aFileName1,const TDesC& aFileName2) +00413 { +00414 TPtr8 imageFromFilePtr = LoadImageIntoMemoryLC(aFileName1); +00415 +00416 // Create CImageTransform object and push it on to the cleanup stack +00417 CImageTransform* imageTransform = CImageTransform::NewL(iFs); +00418 CleanupStack::PushL(imageTransform); +00419 +00420 imageTransform->SetSourceDataL(imageFromFilePtr); +00421 imageTransform->SetDestFilenameL(aFileName2); +00422 imageTransform->SetDestSizeInPixelsL(TSize(160, 120), ETrue); +00423 imageTransform->SetPreserveImageData(ETrue); +00424 imageTransform->SetupL(); +00425 +00426 // Call Transform() function of CImageTransform for image transform operation +00427 // See Note 1 +00428 CActiveListener* activeListener = CreateAndInitializeActiveListenerLC(); +00429 +00430 // Call Transform() function of CImageTransform for image transform operation +00431 imageTransform->Transform(activeListener->iStatus); +00432 +00433 // See Note 2 +00434 CActiveScheduler::Start(); +00435 User::LeaveIfError(activeListener->iStatus.Int()); +00436 +00437 +00438 CleanupStack::PopAndDestroy(3); // activeListener, imageTransform and imageInMemory +00439 } +00440 +00441 +00452 void CIclExample::AddThumbnailToJpegFileL(const TDesC& aSrcFileName, const TDesC& aDesFileName) +00453 { +00454 // Create a CImageTransform object and push it on to the cleanup stack +00455 CImageTransform* imageTransform = NULL; +00456 +00457 imageTransform = CImageTransform::NewL(iFs); +00458 CleanupStack::PushL(imageTransform); +00459 +00460 imageTransform->SetSourceFilenameL(aSrcFileName); +00461 imageTransform->SetDestFilenameL(aDesFileName); +00462 imageTransform->SetDestSizeInPixelsL(TSize(160, 120), ETrue); +00463 imageTransform->SetOptionsL(CImageTransform::EThumbnail); +00464 imageTransform->SetupL(); +00465 +00466 // encode the image to add thumbnail +00467 // See Note 1 +00468 CActiveListener* activeListener = CreateAndInitializeActiveListenerLC(); +00469 +00470 // Call Transform() function of CImageTransform for image transform operation +00471 imageTransform->Transform(activeListener->iStatus); +00472 +00473 // See Note 2 +00474 CActiveScheduler::Start(); +00475 User::LeaveIfError(activeListener->iStatus.Int()); +00476 +00477 +00478 CleanupStack::PopAndDestroy(2); // activeListener and imageTransform +00479 } +00480 +00481 +00493 void CIclExample::AddExifDataToJpegFileL(const TDesC& aFileName) +00494 { +00495 HBufC8* encodedImageDescriptor = NULL; +00496 +00497 // Create the encoder, passing a buffer to store the encoded image +00498 CJPEGExifEncoder* exifEncoder = static_cast<CJPEGExifEncoder*>(CImageEncoder::DataNewL(encodedImageDescriptor, CImageEncoder::EOptionNone, KImageTypeJPGUid)); +00499 CleanupStack::PushL(exifEncoder); +00500 +00501 // Create a MExifMetadata object and initializes to metadata associated with CJPEGexifEncoder +00502 MExifMetadataWriter* metaData = exifEncoder->ExifMetadata(); +00503 +00504 // Create a TExifWriterUtility object to write the metadata in to the image +00505 TExifWriterUtility exifWriteUtility(metaData); +00506 +00507 HBufC8* buf8ParamWriteVersion = KBuf8ParamWriteVersion().AllocLC(); +00508 +00509 User::LeaveIfError(exifWriteUtility.SetImageDescription(buf8ParamWriteVersion)); +00510 +00511 CleanupStack::PopAndDestroy(buf8ParamWriteVersion); +00512 +00513 +00514 // Create a CFbsBitmap to store the source bitmap to encode +00515 CFbsBitmap* sourceBitmap = new(ELeave) CFbsBitmap; +00516 CleanupStack::PushL(sourceBitmap); +00517 +00518 User::LeaveIfError(sourceBitmap->Create(TSize(20,30), EColor16M)); +00519 User::LeaveIfError(sourceBitmap->Load(aFileName)); +00520 +00521 // Create CFrameImageData object and push it on the cleanup stack +00522 CFrameImageData* frameImageData = CFrameImageData::NewL(); +00523 CleanupStack::PushL(frameImageData); +00524 +00525 // See Note 1 +00526 CActiveListener* activeListener = CreateAndInitializeActiveListenerLC(); +00527 +00528 // Convert the image +00529 exifEncoder->Convert(&activeListener->iStatus, *sourceBitmap, frameImageData); +00530 +00531 // See Note 2 +00532 CActiveScheduler::Start(); +00533 User::LeaveIfError(activeListener->iStatus.Int()); // encode complete either display the image or report an error. +00534 +00535 +00536 // Just verifying the presence of some output. +00537 sourceBitmap->Save(_L("c:\\ICLExample\\addexifbitmap.mbm")); +00538 +00539 +00540 CleanupStack::PopAndDestroy(4); // activeListener, frameImageData, sourceBitmap and exifEncoder +00541 +00542 +00543 // We can use the descriptor here +00544 +00545 // And as we took ownership back, we need to push into the cleanup stack to make sure no +00546 // memory leaks take place if any leave later +00547 +00548 CleanupDeletePushL(encodedImageDescriptor); +00549 +00550 +00551 // Just verifying the presence of some output. +00552 +00553 RFile file; +00554 +00555 User::LeaveIfError(file.Replace(iFs, _L("c:\\ICLExample\\addexifdescriptor.mbm"), EFileWrite)); +00556 CleanupClosePushL(file); +00557 +00558 User::LeaveIfError(file.Write(*encodedImageDescriptor)); +00559 +00560 CleanupStack::PopAndDestroy(&file); +00561 +00562 +00563 CleanupStack::PopAndDestroy(encodedImageDescriptor); +00564 } +00565 +00566 +00578 void CIclExample::EncodeBitmapToFileUsingOperationExtensionL(const TDesC& aSrcFileName, const TDesC& aDestFileName) +00579 { +00580 // Create the encoder, passing the filename. +00581 // If the image is not recognised or valid then the call will leave with an error +00582 CImageEncoder* jpegImageEncoder = CImageEncoder::FileNewL(iFs, aDestFileName, CImageEncoder::EOptionNone, KImageTypeJPGUid); +00583 CleanupStack::PushL(jpegImageEncoder); +00584 +00585 // Create a CFbsBitmap to store the source bitmap to encode +00586 CFbsBitmap* sourceBitmap = new(ELeave) CFbsBitmap; +00587 CleanupStack::PushL(sourceBitmap); +00588 +00589 User::LeaveIfError(sourceBitmap->Load(aSrcFileName)); +00590 +00591 // Create operation extension +00592 TImageConvOperation* operation = jpegImageEncoder->OperationL(); +00593 +00594 // Add Rotate 90degrees operation +00595 operation->AddOperationL(TImageConvOperation::ERotation90DegreesClockwise); +00596 // NOTE: Multiple operations can be added +00597 +00598 // See Note 1 +00599 CActiveListener* activeListener = CreateAndInitializeActiveListenerLC(); +00600 +00601 // Convert the image +00602 jpegImageEncoder->Convert(&activeListener->iStatus, *sourceBitmap, NULL); +00603 +00604 // See Note 2 +00605 CActiveScheduler::Start(); +00606 User::LeaveIfError(activeListener->iStatus.Int());// encode complete either display the image or report an error. +00607 +00608 CleanupStack::PopAndDestroy(3, jpegImageEncoder); // jpegImageEncoder, sourceBitmap and activeListener +00609 } +