久久久久久久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 | 亚洲视频手机在线 | 成人在线视频免费观看 | 二区亚洲| 成人国产精品 | 毛片黄| 干出白浆视频 | 久久香蕉精品视频 | 亚洲精品中文字幕 | 红色av社区 | 久久网站黄 | 精品久久亚洲 | 正在播放亚洲 | 国产亚洲一区精品 | 成人精品在线 | 亚洲成人中文字幕 | 中文字幕亚洲一区二区三区 | 日本国产一区二区 | 中文字幕一区在线观看视频 | 国产做爰| 精品欧美一区二区精品久久久 | 国产成人午夜高潮毛片 | 99精品一区二区 | 国产区高清| 91久久国产精品 | 久久久国| 国产成人99久久亚洲综合精品 | 亚洲一区二区不卡在线观看 | www.日韩高清 | 国产成人av在线播放 | 色综合中文 | 三级高清 | 一二三四在线视频观看社区 | 99亚洲精品 | 成人做爰www免费看视频网站 | 中文字幕在线观看一区 | 免费麻豆视频 | 老妇激情毛片免费 | 国产一区二区在线视频 | 久久久一区二区三区四区 | 欧美在线一二三 |