Storing a Picture Tutorial

This topic provides an example of storing a picture in a direct file store (including the creation of a picture header).

      
       
      
      _LIT(KFileName,"C:\\grpict.dat");
    
// Create (replace, if it exists) the direct file store
CDirectFileStore* store = CDirectFileStore::ReplaceLC(fsSession,KFileName,EFileWrite);
// Must say what kind of file store.
iStore->SetTypeL(KDirectFileStoreLayoutUid);
    
// Create picture header
TPictureHeader header;
header.iPicture = iPicture;
header.iSize = TSize(iPicture->SpecToFactor()*40,iPicture->SpecToFactor()*40);
header.iPictureType = KUidExampleSmileyPicture;
    
// Store picture header and picture
CStoreMap* map=CStoreMap::NewLC(*store);
TStreamId id = iPicture->StoreL(*store);
map->BindL(iPicture,id);
    
RStoreWriteStream stream(*map);
TStreamId headerId = stream.CreateLC(*store);
header.ExternalizeL(stream);
stream.CommitL();
map->Reset();
CleanupStack::PopAndDestroy(2); // stream, map
    
// Make header stream the root stream
store->SetRootL(headerId);
    
// Close store
CleanupStack::PopAndDestroy();
     
  1. Create a direct file store into which to store the picture.

  2. Create a picture header object and set its attributes: iPicture is assumed to be picture object, derived from CPicture .

  3. Store the picture header and picture in the file store.

  4. Store the picture data and picture header using a store map as a temporary repository for the stream ID of the picture data stream. Store the stream ID as an element of the picture header's externalized stream to link the picture header’s stream and the picture data’s stream.