locked
BitmapMetadata file dependency RRS feed

  • Question

  • Hello,
    I want to read metadata from a bitmap and cache it for later reuse without needing to access the file on disk. Is it possible just to keep an instance to the BitmapMetadata class? Or will it keep whole bitmap in memory/opened file? The BitmapSource does not contain Dispose method so I don't know how could I test it...

    EDIT: I've tried to delete the file after loading the metadata, but the explorer says it is locked. How can I unlock it explicitly?

    Thanks for any hint,
    Jan
    • Edited by Jan Kučera Saturday, June 7, 2008 5:16 PM edit
    Saturday, June 7, 2008 1:29 PM

Answers

  • BitmapDecoder referenced the source image and has it's own internal reference to it. BitmapMetadata uses WIC to read the image's metadata. If you want to use it on web server, I can advice you to read bitmapstream, create your own hashtable of metadata by using BitmapMetadata class then close and dispose the stream. This way you'll have all nessesery information in external hashtable, but source images will be disposed.
    Tamir http://blogs.microsoft.co.il/blogs/tamir
    If your question was answered, please mark it.
    • Marked as answer by Marco Zhou Friday, June 13, 2008 9:47 AM
    Sunday, June 8, 2008 4:40 PM

All replies

  • You not really need BitmapSource. You have BitmapDecoder to read BitmapMetadata. Once you have it, you can safely dispose Encoder. The reason, you cannot delete image is not BitmapMetadata. It simple in use by BitmapSource (or Control it binded to) 
    Tamir http://blogs.microsoft.co.il/blogs/tamir If your question was answered, please mark it.
    Sunday, June 8, 2008 8:35 AM
  • Hi Tamir,
    thanks for answer. Well are there any details how does the loading and file manipulation work? I've played a bit with that and discovered, that when I construct BitmapDecoder, it reads about 20K from disk (the image has about 200K). I can get first frame's metadata then, which does not read any data more. But if I close the stream at this point, later enumeration of metadata fails (no entries). If I call Clone on the metadata, I can close the stream without troubles, but all 200K is read during cloning. I wonder, does the BitmapMetadata class have any idea to which bitmap it belongs? Or is there any handle (like WIC one) kept open?

    Actually it seems that the BitmapDecoder has its own internal cache, does it make sense to create my own cache with metadata then? (I'm going to use this on web server.)

    Jan
    • Edited by Jan Kučera Sunday, June 8, 2008 3:15 PM typo
    Sunday, June 8, 2008 3:09 PM
  • BitmapDecoder referenced the source image and has it's own internal reference to it. BitmapMetadata uses WIC to read the image's metadata. If you want to use it on web server, I can advice you to read bitmapstream, create your own hashtable of metadata by using BitmapMetadata class then close and dispose the stream. This way you'll have all nessesery information in external hashtable, but source images will be disposed.
    Tamir http://blogs.microsoft.co.il/blogs/tamir
    If your question was answered, please mark it.
    • Marked as answer by Marco Zhou Friday, June 13, 2008 9:47 AM
    Sunday, June 8, 2008 4:40 PM