2010-02-23 97 views
2

我得到的是一個截圖製作應用程序。 (設法序列化,感謝上帝!)當點擊一個按鈕時,通過訪問處理類的方法獲取屏幕截圖。現在棘手的部分是該類具有用於以上述結果操作的另一種方法,以與調用相應處理方法時相比的方式,創建(示出)窗口並且位圖圖像應該進入顯示容器中那個窗戶。問題是,到目前爲止,我已經注意到,在WPF中,圖像控件的源不能歸屬於存儲圖像的變量。我怎樣才能顯示存儲在該變量中的圖像,而不必先保存它,得到uri等。 ?有沒有辦法在存儲在內存中的WPF中顯示圖像?

回答

1

感謝鏈接slugster。以下是我做的:

MemoryStream ms = new MemoryStream(); 
sBmp = gBmp; //note: gBmp is a variable that stores the captured image and passes it on to the method that uses sBMP as a distribuitor of the variable holding the captured image data 
//variable that holds image 
sBmp.Save(ms,ImageFormat.Bmp); 
//my buffer byte 
byte[] buffer = ms.GetBuffer(); 
//Create new MemoryStream that has the contents of buffer 
MemoryStream bufferPasser = new MemoryStream(buffer); 
//Creates a window with parents classthatholdsthismethod and null 
Edit childEdit = new Edit(this, null); 
childEdit.Show(); 
//I create a new BitmapImage to work with 
BitmapImage bitmap = new BitmapImage(); 
bitmap.BeginInit(); 
bitmap.StreamSource = bufferPasser; 
bitmap.EndInit(); 
//I set the source of the image control type as the new BitmapImage created earlier. 
childEdit.imgImageCanvas.Source = bitmap; 
childEdit.Activate(); 

我基本上結合我所上的一些信息我如何傳遞一個bmp到memstream發現這些網頁發現。我得到這個工作100%:)

相關問題