一个BitmapFrame和BitmapImage的WPF中之间的区别 [英] Difference between a BitmapFrame and BitmapImage in WPF

查看:2285
本文介绍了一个BitmapFrame和BitmapImage的WPF中之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个BitmapFrame和BitmapImage的WPF中之间的区别是什么?你会在哪里使用每个(即为什么要使用BitmapFrame而不是BitmapImage的?)

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

推荐答案

您应该坚持使用抽象类<一href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapsource.aspx">BitmapSource如果你需要获取位,甚至的ImageSource 如果你只是想画它。

You should stick to using the abstract class BitmapSource if you need to get at the bits, or even ImageSource if you just want to draw it.

的实施BitmapFrame是实施只是面向对象的性质显示通过。你真的不应该有任何需要的实现之间的区别。 BitmapFrames可能包含一些额外信息(元数据),但通常不过是一种成像应用程序会关心。

The implementation BitmapFrame is just the object oriented nature of the implementation showing through. You shouldn't really have any need to distinguish between the implementations. BitmapFrames may contain a little extra information (metadata), but usually nothing but an imaging app would care about.

您会发现,从的BitmapSource继承这些其他类:

You'll notice these other classes that inherit from BitmapSource:

  • BitmapFrame
  • 的BitmapImage
  • CachedBitmap
  • Col​​orConvertedBitmap
  • CroppedBitmap
  • FormatConvertedBitmap
  • RenderTargetBitmap
  • TransformedBitmap
  • WriteableBitmap的

您可以通过构造的BitmapImage对象从一个URI一个的BitmapSource:

You can get a BitmapSource from a URI by constructing a BitmapImage object:

Uri uri = ...;
BitmapSource bmp = new BitmapImage(uri);
Console.WriteLine("{0}x{1}", bmp.PixelWIdth, bmp.PixelHeight);

本的BitmapSource也可能来自德codeR。在这种情况下,你是间接使用BitmapFrames。

The BitmapSource could also come from a decoder. In this case you are indirectly using BitmapFrames.

Uri uri = ...;
BitmapDecoder dec = BitmapDecoder.Create(uri, BitmapCreateOptions.None, BitmapCacheOption.Default);
BitmapSource bmp = dec.Frames[0];
Console.WriteLine("{0}x{1}", bmp.PixelWIdth, bmp.PixelHeight);

这篇关于一个BitmapFrame和BitmapImage的WPF中之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆