久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

c# wpf 多邊形到位圖不顯示任何內容

c# wpf polygon to bitmap not displaying anything(c# wpf 多邊形到位圖不顯示任何內容)
本文介紹了c# wpf 多邊形到位圖不顯示任何內容的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

抱歉,如果您認為這個問題已經得到解答,我確實到處尋找,試圖找出這樣做的原因,但它沒有顯示任何內容.這是我所有的代碼:

Sorry if you think this question was already answered, I did look everywhere trying to find out how come when I do this, it is not displaying anything. This is all my code:

Polygon hexagon = new Polygon();
PointCollection pc = new PointCollection();
double side = 25;
double xOffset = 0, yOffset = 0;
double r = System.Math.Cos((System.Math.PI / 180) * 30) * side;
double h = System.Math.Sin((System.Math.PI / 180) * 30) * side;

//Create the 6 points needed to create a hexagon
pc.Add(new Point(xOffset, yOffset)); //Point 1
pc.Add(new Point(xOffset + side, yOffset)); //Point 2
pc.Add(new Point(xOffset + side + h, yOffset + r)); //Point 3
pc.Add(new Point(xOffset + side, yOffset + 2 * r)); //Point 4
pc.Add(new Point(xOffset, yOffset + 2 * r)); //Point 5
pc.Add(new Point(xOffset - h, yOffset + r)); //Point 6

hexagon.Stroke = Brushes.Blue;
hexagon.StrokeThickness = 1;
hexagon.Fill = Brushes.LightBlue;
hexagon.Points = pc;

RenderTargetBitmap bmp = new RenderTargetBitmap(200, 200, 96, 96, PixelFormats.Default);
bmp.Render(hexagon);
img.Source = bmp;

我創建了一個六邊形作為多邊形對象,并使用 RenderTargetBitmap 嘗試將多邊形轉換為位圖,但它似乎沒有顯示我能看到的任何內容.我還添加了一個畫布并在那里添加了 Polygon 對象,這似乎有效.只是在轉換為位圖時.我真的不知道我的代碼有什么問題.我現在在主窗口加載事件中擁有一切.

I created a hexagon as a polygon object and I used RenderTargetBitmap to try to convert the polygon to a bitmap but it does not seem to be displaying anything that I can see. I have also added a canvas and added the Polygon object there and that seems to work. It is just when converting to a bitmap. I really am at a lost as to what is wrong in my code. I have everything right now in the main windows loaded event.

將不勝感激,謝謝.

解決方案可能很簡單或者我忽略了一些東西,希望解決方案很簡單:)

The solution may be simple or something I overlooked, hopefully the solution is simple :).

推薦答案

WPF UIElement 必須在可見之前進行布局.它必須至少獲得一個 MeasureArrange 調用,在那里它獲得一個可用的 Size 和一個最終的排列 Rect(通常來自它的父面板).將新創建的元素渲染到 RenderTargetBitmap 中時,您將手動調用這些方法,并為 Size 和 Rect 設置適當的值:

A WPF UIElement has to be laid out before being visible. It has to get at least one Measure and Arrange call, where it gets an available Size and a final arrange Rect (usually from its parent Panel). When rendering a newly created element into a RenderTargetBitmap, you would call these methods manually, with appropriate values for the Size and Rect:

...
hexagon.Measure(new Size(200, 200)); // adjust this to your needs
hexagon.Arrange(new Rect(0, 0, 200, 200)); // adjust this to your needs

var bmp = new RenderTargetBitmap(200, 200, 96, 96, PixelFormats.Default);
bmp.Render(hexagon);

這篇關于c# wpf 多邊形到位圖不顯示任何內容的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Right-click on a Listbox in a Silverlight 4 app(右鍵單擊 Silverlight 4 應用程序中的列表框)
WPF c# webbrowser scrolls over top menu(WPF c# webbrowser 在頂部菜單上滾動)
C# Console app - How do I make an interactive menu?(C# 控制臺應用程序 - 如何制作交互式菜單?)
How to avoid duplicate form creation in .NET Windows Forms?(如何避免在 .NET Windows Forms 中創建重復的表單?)
UI Automation Control Desktop Application and Click on Menu Strip(UI自動化控制桌面應用程序并單擊菜單條)
Removing thin border around the menuitems(刪除菜單項周圍的細邊框)
主站蜘蛛池模板: 久久国产精品精品 | 久热久热 | 国产不卡在线观看 | 亚洲一区二区三区四区五区中文 | 毛片区 | 高清黄色 | 国产精品国产三级国产aⅴ中文 | 日韩区| 日韩欧美精品 | 久久噜噜噜精品国产亚洲综合 | 视频一区二区在线 | 真人毛片 | h视频在线免费看 | 日韩精品免费 | 91精品国产综合久久婷婷香蕉 | 91pron在线| 91资源在线观看 | 国内精品久久久久久久影视简单 | 国产三区在线观看视频 | 国产aa| 天堂成人国产精品一区 | 91精品国产综合久久久久久丝袜 | 男人天堂网址 | 亚洲色图第一页 | 国产69精品久久久久777 | 97精品一区二区 | 高清欧美性猛交xxxx黑人猛交 | 国产高清在线精品 | 99精品九九 | 中文字幕一级 | 精品国产精品三级精品av网址 | 日韩电影在线一区 | 一区二区三区小视频 | 国产麻豆一区二区三区 | 涩涩视频网站在线观看 | 欧洲毛片 | 亚洲精品国产成人 | 一级毛片色一级 | 欧美日韩一区二区三区视频 | 中文字幕一区二区三区在线观看 | 欧美激情精品久久久久 |