Hey,Lyubo.
My current program is modified to have only this code to look for errors.
But still couldn't figure out the problem, the only possibility of error lies in this expression: var imageWidth = GraphicsUnit.Pixel.Convert (imageWidthPx, diagram.MeasureUnit);
MainWindow.xmal:
<Window
xmlns="
http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="
http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="
http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="
http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MeasurementUnit"
xmlns:diag="
http://mindfusion.eu/diagramming/wpf" x:Class="MeasurementUnit.MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" Loaded="Window_Loaded">
<Grid>
<diag:Ruler Name="ruler" ShowIcon="False" FontSize="11" Grid.Row="1" Grid.Column="1" BorderBrush="Black">
<diag:Diagram x:Name="diagram"
AllowDrop="True"
VerticalAlignment="Top"
HorizontalAlignment="Left"
DefaultShape="RoundRect"
Behavior="Pan"
GridSizeX="15" GridSizeY="15" RestrictItemsToBounds="InsideOnly" RightButtonActions="None"
Bounds="-500,-500,2000,2000"
>
</diag:Diagram>
</diag:Ruler>
</Grid>
</Window>
MainWindow.xmal.cs:
using Microsoft.Win32;
using MindFusion.Diagramming.Wpf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace MeasurementUnit
{
/// <summary>
/// MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
diagram.MeasureUnit = GraphicsUnit.Millimeter;
ruler.Unit = RulerUnit.Millimeter;
OpenFileDialog openfiledialog = new OpenFileDialog
{
Filter = "*.jpg;*.png;*.jpeg;*.bmp;*.gif|*.*"
};
if ((bool)openfiledialog.ShowDialog())
{
ImageManipulation(openfiledialog.FileName);
}
}
static ShapeNode imageNode;
private void ImageManipulation(string path)
{
var myImage = new BitmapImage(new Uri(path, UriKind.Relative));
var imageWidthPx = myImage.PixelWidth * 96 / myImage.DpiX;
var imageHeightPx = myImage.PixelHeight * 96 / myImage.DpiY;
var imageWidth = GraphicsUnit.Pixel.Convert(imageWidthPx, diagram.MeasureUnit);
var imageHeight = GraphicsUnit.Pixel.Convert(imageHeightPx, diagram.MeasureUnit);
imageNode = diagram.Factory.CreateShapeNode(0, 0, imageWidth, imageHeight);
imageNode.Image = myImage;
imageNode.Shape = Shapes.Rectangle;
imageNode.CustomDraw = CustomDraw.Additional;
imageNode.ImageAlign = ImageAlign.Fit;
}
}
}
Figure 1 is the picture I tested, you can check.