Difference between a BitmapFrame and BitmapImage in WPF

前端 未结 3 1494
情话喂你
情话喂你 2021-02-13 22:03

What is the difference between a BitmapFrame and BitmapImage in WPF? Where would you use each (ie. why would you use a BitmapFrame rather than a BitmapImage?)

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-13 22:23

    The accepted answer is incomplete (not to suggest that my answer is complete either) and my addition may help someone somewhere.

    The reason (albeit the only reason) I use a BitmapFrame is when I access the individual frames of a multiple-framed TIFF image using the TiffBitmapDecoder class. For example,

    TiffBitmapDecoder decoder = new TiffBitmapDecoder(
        new Uri(filename), 
        BitmapCreateOptions.None, 
        BitmapCacheOption.None);
    
    for (int frameIndex = 0; frameIndex < decoder.Frames.Count; frameIndex++)
    {
        BitmapFrame frame = decoder.Frames[frameIndex];
        // Do something with the frame
        // (it inherits from BitmapSource, so the options are wide open)
    }
    

提交回复
热议问题