WPF中的BitmapFrame和BitmapImage有什麼不同?你會在哪裏使用每個(即爲什麼要使用一個BitmapFrame而不是一個BitmapImage的?)WPF中的BitmapFrame和BitmapImage的區別
10
A
回答
12
你應該堅持使用抽象類BitmapSource,如果你需要獲取的位,甚至ImageSource,如果你只是想畫出來。
實現BitmapFrame僅僅是實現的面向對象的性質。您實際上不需要區分這些實現。 BitmapFrames可能包含一些額外的信息(元數據),但通常只有成像應用程序纔會關心。
你會發現,從繼承的BitmapSource這些其他類:
- BitmapFrame
- 的BitmapImage
- CachedBitmap
- ColorConvertedBitmap
- CroppedBitmap
- FormatConvertedBitmap
- RenderTargetBitmap
- TransformedBitmap
- WriteableBitmap的
您可以通過構建一個BitmapImage的對象得到一個URI一個的BitmapSource:
Uri uri = ...;
BitmapSource bmp = new BitmapImage(uri);
Console.WriteLine("{0}x{1}", bmp.PixelWIdth, bmp.PixelHeight);
的的BitmapSource也可能來自一個解碼器。在這種情況下,您是間接使用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);
0
BitmapFrame是圖像操作的低級別原語。通常在您想要將某個圖像從一種格式編碼/解碼到另一種格式時使用。
BitmapImage是更高層次的抽象,具有一些整齊的數據綁定屬性(UriSource等)。
如果你只是顯示圖像,並希望一些微調BitmapImage是你所需要的。
如果你正在做低級圖像處理,那麼你將需要BitmapFrame。
0
我知道這是一個古老的問題,但接受的答案是不完整的(不建議我的答案是完整的),我的補充可能有助於某人某處。
原因(儘管只有原因)我使用BitmapFrame是當我訪問使用TiffBitmapDecoder
類的多幀TIFF圖像的個別幀。例如,
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)
}
相關問題
- 1. BitmapFrame轉換爲BitmapImage?
- 2. WPF組合框中的BitmapFrame
- 3. 序列化WPF中的BitmapImage
- 4. WPF中的BitmapImage to Byte []
- 5. WPF中的第二層BitmapImage
- 6. 創建的BitmapImage WPF
- 7. wpf中datagrid和grid之間的區別
- 8. 使用Flex的圖像和BitmapImage之間的區別?
- 9. 是否可以將文本框轉換爲BitmapImage或BitmapFrame?
- 10. 的BitmapImage的SourceStream是WPF
- 11. WPF BitmapImage not display
- 12. RenderTargetBitmap到的BitmapImage在WPF
- 13. 加載WPF中的BitmapImage的來源?
- 14. Touch和Stylus WPF有什麼區別WPF
- 15. Winforms,WPF和城域之間的區別?
- 16. Prism v4 WPF和Silverlight的區別
- 17. vbHidden和Windows.Visibility.Hidden之間的區別WPF vb.net
- 18. TextBlock.BaselineOffset Silverlight和WPF之間的區別
- 19. Textbox和RichTextbox wpf之間的區別?
- 20. 在WPF中區別選擇和拖動
- 21. WPF中ListView和GridView有什麼區別?
- 22. WPF中StaticResources和DynamicResources有什麼區別?
- 23. WPF中TableColumn和GridColumn的Auto和Star之間的區別
- 24. WPF控件SetValue的區別
- 25. Winforms中的事件和WPF中的命令有什麼區別?
- 26. WPF驗證中的ValidatesOnNotifyDataErrors和ValidatesOnDataErrors和NotifyOnValidationError有什麼區別?
- 27. BitmapImage的PixelWidth和UriSource
- 28. 的BitmapImage和位圖
- 29. WPF BitmapImage切成兩半
- 30. WPF BitmapImage內存問題
你甚至可以如何使用ImageSource?你如何加載一個帶有Uri的BitmapSource? – 2008-09-30 22:57:50