2013-01-06 19 views
2

我無法理解如何使用FormatConvertedBitmap將我從Pbgra32轉換爲Bgr32WriteableBitmap。我正在構建的應用程序最初使用Bgr32,並且我引入了WriteableBitmapEx(使用Pbgra32)來翻轉圖像。現在,我需要將Pbgra32轉換回Bgr32以保持與程序其餘部分的一致性。以下是我所擁有的:使用FormatConvertedBitmap從Pbgra32轉換爲Bgr32 PixelFormats

FormatConvertedBitmap newFormat = new FormatConvertedBitmap(this.colorBitmap, PixelFormats.Bgr32, null, 0); 

......我認爲這是正確的做轉換。但是,我不確定如何從中檢索WriteableBitmap。

+0

你不能僅僅通過傳遞'newFormat' [本構造(HTTP創建一個新的WriteableBitmap的工作.microsoft.com/EN-US /庫/ aa346377.aspx)? – Clemens

回答

1

您現在處於正確的軌道上,您只需將其轉換爲WriteableBitmap即可將其存儲爲一個整體。要做到這一點,您必須首先將其投射到BitmapSource並創建一個新的WriteableBitmap。因此,像這樣:// MSDN:

WriteableBitmap yourConvertedPicture = new WriteableBitmap(
    (BitmapSource)(new FormatConvertedBitmap(thePictureToConvert, PixelFormats.Bgr32, null, 0)) 
); 

這也將轉換爲任何其他PixelFormat