I have a 27 x 27 pixel image that I am displaying in WPF but it displays larger than the size of the window.
How can I get it to display its actual size?
XAML:
<Window x:Class="TestImage23434.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<StackPanel x:Name="MainStackPanel"/>
</Window>
Code Behind:
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System;
namespace TestImage23434
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
TextBlock tb = new TextBlock();
tb.Text = "above image ";
MainStackPanel.Children.Add(tb);
Image img = new Image();
img.Source = new BitmapImage(new Uri(@"C:\test\circle.png"));
img.HorizontalAlignment = HorizontalAlignment.Left;
img.VerticalAlignment = VerticalAlignment.Top;
MainStackPanel.HorizontalAlignment = HorizontalAlignment.Left;
MainStackPanel.VerticalAlignment = VerticalAlignment.Top;
MainStackPanel.Children.Add(img);
TextBlock tb2 = new TextBlock();
tb2.Text = "below image";
MainStackPanel.Children.Add(tb2);
}
}
}