Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 如何保持图像的大小、位置和旋转,然后恢复它?_Wpf_Image_Xaml_Xamlwriter - Fatal编程技术网

Wpf 如何保持图像的大小、位置和旋转,然后恢复它?

Wpf 如何保持图像的大小、位置和旋转,然后恢复它?,wpf,image,xaml,xamlwriter,Wpf,Image,Xaml,Xamlwriter,在WPF中,我有一个图像,它被放到InkCanvas上并作为子对象添加: ImageInfo image_Info = e.Data.GetData(typeof(ImageInfo)) as ImageInfo; if (image_Info != null) { Image image = new Image(); image.Width = image_Info.Width * 4;

在WPF中,我有一个图像,它被放到InkCanvas上并作为子对象添加:

    ImageInfo image_Info = e.Data.GetData(typeof(ImageInfo)) as ImageInfo;
        if (image_Info != null)
        {
            Image image = new Image();
            image.Width = image_Info.Width * 4;
            image.Stretch = Stretch.Uniform;
            image.Source = new BitmapImage(image_Info.Uri);
            Point position = e.GetPosition(ic);

            InkCanvas.SetLeft(image, position.X);
            InkCanvas.SetTop(image, position.Y);
            ic.Children.Add(image);
     }
然后通过装饰器移动图像并调整其大小。然后将其保存到数据库中,如下所示:

 public List<string> Children;

 var uiList = ic.Children.Cast<UIElement>().ToList();
            foreach (var p in uiList)
            {
                string uis = System.Windows.Markup.XamlWriter.Save(p);
                s.Add(uis);
            }
            Children = s;
(图像源打包为应用程序资源)

如何保持图像的大小、位置和旋转,然后恢复图像

蒂亚

  • 或者,您可以向DB表中添加其他字段,用于大小/位置/旋转,并在其中存储信息

  • 或者,您可以将这些字段以逗号(,)分隔并存储在
    图像
    控件的
    标记
    字段中<代码>

  • 您还可以将整个处理过的图像保存为数据库中的
    byte[]


    请告诉我这是否解决了您手头的问题。

    事实证明,移除装饰器后,上述代码确实可以正常工作。但是,我非常喜欢您将附加信息作为字符串存储在标记中的想法。我相信xamlwriter将正确地编写用于持久化的字符串数据,这将允许在前端和数据库之间进行图像识别。好主意。谢谢。你根本不应该序列化和反序列化XAML。最好使用描述当前视图的所有必要数据创建适当的模型类。然后加载并保存该模型类的实例。
    "<Image Source="pack://application:,,,/Images/Female - Front.png" Stretch="Uniform" Width="Auto" InkCanvas.Top="296" InkCanvas.Left="695" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" /> "
    
    foreach (string s in behavior.Children)
                {
                    var stringReader = new StringReader(s);
                    var xmlReader = System.Xml.XmlReader.Create(stringReader, new System.Xml.XmlReaderSettings());
    
                    Image b = (Image)System.Windows.Markup.XamlReader.Load(xmlReader);
                    ic.Children.Add(b);
                }