我在地图上画了一个单元格墙,它的大小错误。我在调试器中检查了图像的高度,它与正确的 cellSize 大小相同,但在视觉上它看起来更短,并且它的开头没有绘制在正确的位置。就像它被画在两端的顶部一样。当我更改图像的高度属性时,它不会使图像变大。这不是如何使用高度和宽度设置图像大小吗?
这是代码。
private void calculateWall(int wall, int cell)
{
int[] mapData = this.getMapData(cell);
int startOfCol = mapData[0];
int endOfCol = mapData[1];
int startOfRow = mapData[2];
int endOfRow = mapData[3];
CellSide rightSide = this.getCells()[cell].myRightWall;
CellSide bottomSide = this.getCells()[cell].myBottomWall;
float thickness = myMap.myCellSize * (float)0.1;
Math.Round(thickness, 0);
int newThickness = Convert.ToInt32(thickness);
float height = myMap.myCellSize * (float)0.2;
Math.Round(height, 0);
int newHeight = Convert.ToInt32(height);
if (rightSide.hasWall == 1)
{
Image verticalWall = new Image();
// Create source.
BitmapImage bi = new BitmapImage();
// BitmapImage.UriSource must be in a BeginInit/EndInit block.
bi.BeginInit();
bi.UriSource = new Uri("verticalWall.jpg", UriKind.RelativeOrAbsolute);
bi.EndInit();
// Set the image source.
verticalWall.Source = bi;
verticalWall.Width = newThickness;
verticalWall.Height = myMap.myCellSize;
verticalWall.SetValue(Canvas.TopProperty, Convert.ToDouble(startOfRow));
verticalWall.SetValue(Canvas.LeftProperty, Convert.ToDouble(endOfCol - (newThickness / 2)));
verticalWall.IsHitTestVisible = false;
this.view.pbxMap.Children.Add(verticalWall);
}