[英]How can you specify the coordinates that you want a bitmap to appear on a canvas?
給定一個位圖:
Swamp1 = new BitmapImage(new Uri("pack://application:,,,/Images/Swamp-Corner-Transparent.png"));
如何指定將在畫布上顯示的坐標:
<Canvas Grid.Column="2" HorizontalAlignment="Right" Height="822" VerticalAlignment="Top" Width="1198" Name="MainCanvas">
<Image Name="MapBorderSource" />
</Canvas>
我以前做過,但是很久以前。 具體來說,我需要在Image
“ MapBorderSource”頂部的Canvas
“ MainCanvas”的坐標X,Y處繪制BitmapImage
“ Swamp1”。 PNG的白色設置為Alpha 0。
在后面的代碼中,您將編寫
var image = new Image
{
Source = new BitmapImage(new Uri(
"pack://application:,,,/Images/Swamp-Corner-Transparent.png"));
};
Canvas.SetLeft(image, x);
Canvas.SetTop(image, y);
MainCanvas.Children.Add(image);
如果您需要將新的Image直接放在MapBorderSource
,也可以放在其他任何子元素之下,則可以編寫
var index = MainCanvas.Children.IndexOf(MapBorderSource) + 1;
MainCanvas.Children.Insert(index, image);
您可以像這樣指定坐標。
<Image Name="MapBorderSource" Canvas.Top="10" Canvas.Left="10" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.