我得到的是一個截圖製作應用程序。 (設法序列化,感謝上帝!)當點擊一個按鈕時,通過訪問處理類的方法獲取屏幕截圖。現在棘手的部分是該類具有用於以上述結果操作的另一種方法,以與調用相應處理方法時相比的方式,創建(示出)窗口並且位圖圖像應該進入顯示容器中那個窗戶。問題是,到目前爲止,我已經注意到,在WPF中,圖像控件的源不能歸屬於存儲圖像的變量。我怎樣才能顯示存儲在該變量中的圖像,而不必先保存它,得到uri等。 ?有沒有辦法在存儲在內存中的WPF中顯示圖像?
2
A
回答
4
您需要從內存流創建圖像,這已被很多人記錄在案。這裏有兩個鏈接,可以讓你開始:
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%:)
相關問題
- 1. WPF:有沒有辦法將圖像保存在Viewport3D中?
- 2. 圖像沒有存儲在緩存中
- 3. 顯示的圖像沒有存儲在網頁內容 - Glassfish 4
- 4. 有沒有辦法在Rails的視圖中存儲變量?
- 5. 有沒有辦法在OllyDbg中打開多個內存轉儲?
- 6. rmagick有沒有辦法轉換圖像在內存
- 7. WPF內存中圖像顯示
- 8. 有沒有辦法讓圖像顯示在ASP.NET和app_offline.htm中?
- 9. 有沒有辦法從chrome的存儲映像中獲取url?
- 10. 顯示存儲在OPENSHIFT_DATA_DIR中的圖像
- 11. 顯示存儲在MongoDb中的圖像
- 12. 有沒有辦法在R中讀寫內存中的文件?
- 13. 有沒有辦法在GameMaker中向玩家顯示內存使用情況?
- 14. 有沒有辦法在一個存儲庫中有一個文件,但沒有在另一個存儲庫中?
- 15. 無法在gridview中顯示圖像(內部存儲)
- 16. 在RecyclerView中顯示Firebase存儲圖像
- 17. 如何顯示存儲在數據庫中的所有圖像
- 18. 有沒有辦法將XML.appendChild函數存儲在變量中?
- 19. 有沒有辦法在WKWebView中設置本地存儲
- 20. 有沒有辦法在Jenkins中存儲整個build.xml文件?
- 21. 有沒有辦法在HTML對象中存儲長HTML腳本
- 22. 有沒有辦法在c#4.5中存儲臨時列表值?
- 23. 有沒有辦法在對象GKScore中存儲int值?
- 24. 有沒有辦法在.dll文件中存儲Delphi窗體?
- 25. 有沒有辦法在Oz中存儲函數/過程調用?
- 26. 有沒有辦法在Ruby on Rails中存儲時間?
- 27. 有沒有辦法將Shopify頁面存儲在git中?
- 28. 有沒有辦法在SELECT語句中存儲變量?
- 29. 有沒有辦法在訪問中存儲時間戳?
- 30. 有沒有辦法在覈心數據中存儲unsigned long?