Symbian3/SDK/Source/GUID-F9471A5D-D239-5B24-A116-2B5B2C1F5C61.dita
changeset 7 51a74ef9ed63
parent 0 89d6a7a84779
equal deleted inserted replaced
6:43e37759235e 7:51a74ef9ed63
       
     1 <?xml version="1.0" encoding="utf-8"?>
       
     2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
       
     3 <!-- This component and the accompanying materials are made available under the terms of the License 
       
     4 "Eclipse Public License v1.0" which accompanies this distribution, 
       
     5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
       
     6 <!-- Initial Contributors:
       
     7     Nokia Corporation - initial contribution.
       
     8 Contributors: 
       
     9 -->
       
    10 <!DOCTYPE concept
       
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
       
    12 <concept xml:lang="en" id="GUID-F9471A5D-D239-5B24-A116-2B5B2C1F5C61"><title>Restoring Pictures Tutorial</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>Pictures can be restored in two different ways. One way is to restore the picture header and restore the data immediately afterwards. The other way is to restore the picture header and defer the loading of the picture data until a later time. </p> <p>This second way is commonly used when loading rich text documents that include pictures. Using a deferred loading scheme, pictures that occur towards the end of a document need not be loaded until they are needed to be displayed, thus economizing on memory use. </p> <section><title>Restoring the picture header</title> <p>This fragment assumes that the picture header is stored in the root stream of the store, making it easy to restore: </p> <codeblock id="GUID-44712CF8-FBB7-5898-B1F9-C43BB82C17EC" xml:space="preserve">// The file used in the example
       
    13 _LIT(KFileName,"C:\\grpict.dat");
       
    14     
       
    15 // Open the direct file store
       
    16 CDirectFileStore* store = CDirectFileStore::OpenLC(fsSession,KFileName,EFileRead);
       
    17     
       
    18 // Read the header stream
       
    19 RStoreReadStream stream;
       
    20 stream.OpenLC(*store,store-&gt;Root());
       
    21 TPictureHeader header;
       
    22 header.InternalizeL(stream);</codeblock> <codeblock id="GUID-8F9F9D3D-36E7-534A-BA05-5FF545487DDB" xml:space="preserve">// Close store
       
    23 CleanupStack::PopAndDestroy(2); // stream, store</codeblock> <ol id="GUID-A3461FFF-48C2-5447-AA8E-E23C3E9696B7"><li id="GUID-12F9B67D-4A85-5648-89BB-B3CA41DCFBC1"><p>Open the direct file store containing the picture. </p> </li> <li id="GUID-F43C5DEB-BFB9-5076-BCEC-61495B3F326A"><p>Open the root stream of the store, and InternalizeL the picture header. </p> </li> <li id="GUID-5E9FDE2A-4E64-5262-92E9-B15870C6D5AD"><p>Close the stream and store. </p> </li> </ol> </section> <section><title>Restoring the picture data: an example of a MPictureFactory-derived class</title> <p>To restore the picture data itself, it must have an associated entry in a picture factory. The picture factory ensures that the picture data in the store is restored to the correct picture type, which is specified by a UID in the picture header. A picture factory can allow a number of different types of picture to be restored, calling the correct constructor for the class indicated by the UID. In the following example code the picture factory allows only pictures of type <codeph>CSmileyPicture</codeph> to be restored, and panics if the picture data in the store is of another type. </p> <p><b>Restoring the picture </b> </p> <codeblock id="GUID-F05D870C-C1D6-5D04-81AE-703F50054191" xml:space="preserve">// The file used in the example
       
    24 _LIT(KFileName,"C:\\grpict.dat");
       
    25     
       
    26 // Open the direct file store
       
    27 CDirectFileStore* store = CDirectFileStore::OpenLC(fsSession,KFileName,EFileRead);
       
    28     
       
    29 // Read the picture
       
    30 TExamplePictureFactory factory;
       
    31 TPictureHeader header;
       
    32 factory.NewPictureL(header,*store);
       
    33 iPicture = (CSmileyPicture *) header.iPicture.AsPtr();
       
    34     
       
    35 // Close store
       
    36 CleanupStack::PopAndDestroy();</codeblock> <p><b>Picture factory </b> </p> <codeblock id="GUID-578BC9C7-9D62-5ADF-A2B5-6601588FE384" xml:space="preserve">class TExamplePictureFactory: public MPictureFactory
       
    37     {
       
    38 public:
       
    39     void NewPictureL(TPictureHeader&amp; aHeader,
       
    40             const CStreamStore&amp; aDeferredPictureStore) const;
       
    41     };
       
    42 </codeblock> <codeblock id="GUID-C5CCB0B1-3D13-581E-8990-15084212BFB3" xml:space="preserve">void TExamplePictureFactory::NewPictureL(TPictureHeader&amp; aHeader,
       
    43             const CStreamStore&amp; aDeferredPictureStore) const
       
    44     {
       
    45     if (aHeader.iPictureType == KUidExampleSmileyPicture)
       
    46         {
       
    47             // Restore new picture from store into 
       
    48             // the TSwizzle, which changes from
       
    49             // stream id to pointer.
       
    50             // Construct CSmileyPicture object and 
       
    51             // restore from stream.
       
    52         if (aHeader.iPicture.IsId())
       
    53             aHeader.iPicture = CSmileyPicture::NewL(aDeferredPictureStore,aHeader.iPicture.AsId());
       
    54         }
       
    55     else
       
    56         {
       
    57             // Leave
       
    58         User::Leave(KErrNoMemory);
       
    59         }
       
    60     }</codeblock> </section> </conbody><related-links><link href="GUID-520AC2F0-009E-51F3-A661-3B6E949F1423.dita"><linktext>Picture Tutorials</linktext> </link> <link href="GUID-5CEE36FC-C5A9-5C4E-9DBC-9C7B5B44EA2F.dita"><linktext>Picture Concepts</linktext> </link> </related-links></concept>