Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between a BitmapFrame and BitmapImage in WPF

Tags:

.net

wpf

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?)

like image 709
Kris Erickson Avatar asked Sep 30 '08 22:09

Kris Erickson


2 Answers

BitmapFrame is a low level primitive for image manipulation. It is usually used when you want to encode/decode some image from one format to another.

BitmapImage is more high level abstraction that has some neat data-binding properties (UriSource, etc).

If you are just displaying images and want some fine tuning BitmapImage is what you need.

If you are doing low level image manipulation then you will need BitmapFrame.

like image 113
ligaz Avatar answered Sep 19 '22 17:09

ligaz


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)
}
like image 30
stritch000 Avatar answered Sep 18 '22 17:09

stritch000