我有一个用户控件库,它将用作另一个窗口的自定义工具提示,用户控件包含引用目录的图像刷的 ImageSource。在窗口内,我有另一个类,它将生成一个图像文件到与 imagebrush 相同的目录。
但是我在运行后得到一个错误。调用堆栈仅包含外部代码。'对与指定绑定约束匹配的'WpfApplication2.MainWindow'类型的构造函数的调用引发了异常。行号“4”和行位置“9”
这是我的片段。
UserControl1.xaml
<UserControl.Resources>
<Style TargetType="Rectangle">
<Setter Property="Fill">
<Setter.Value>
<ImageBrush ImageSource="C:\Users\user\Desktop\wpf\WpfApplication2\WpfApplication2\Images/QR.png" Stretch="Fill" />
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
显示窗口.xaml
xmlns:myToolTip="clr-namespace:WpfControlLibrary2;assembly=WpfControlLibrary2"
<myToolTip:UserControl1 Visibility="Collapsed" x:Name="customToolTip" Width="468" Height="700" />
二维码编码器.cs
public QrCodeEncodercs(string encodeString)
{
QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
QrCode qrCode = new QrCode();
//const string encodeString = "123";
qrEncoder.TryEncode(encodeString, out qrCode);
Renderer renderer = new Renderer(11, System.Drawing.Brushes.Black, System.Drawing.Brushes.White);
renderer.CreateImageFile(qrCode.Matrix, @"C:\Users\user\Desktop\wpf\WpfApplication2\WpfApplication2\Images\QR.png\Images\QR.png",
ImageFormat.Png);
}
显示窗口.xaml.cs
当我运行上面类的构造函数时。上面提到的错误发生了。
qce = new QrCodeEncodercs(videoName);
究竟发生了什么?有什么指导吗?提前致谢。
编辑_ __ _InnerException
InnerException: System.Runtime.InteropServices.ExternalException
HResult=-2147467259
Message=A generic error occurred in GDI+.
Source=System.Drawing
ErrorCode=-2147467259
StackTrace:
at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
at Gma.QrCodeNet.Encoding.Windows.Controls.Renderer.CreateImageFile(BitMatrix matrix, String fileName, ImageFormat imageFormat)
at WpfApplication2.DisplayWindow.QrCodeEncodercs(String encodeString) in c:\Users\user\Desktop\wpf\KinectREAL\WpfApplication2\WpfApplication2\DisplayWindow..xaml.cs:line 127
at WpfApplication2.DisplayWindow.PopulateVideoListAndFirstVideo() in c:\Users\user\Desktop\wpf\KinectREAL\WpfApplication2\WpfApplication2\DisplayWindow..xaml.cs:line 157
at WpfApplication2.DisplayWindow..ctor() in c:\Users\user\Desktop\wpf\KinectREAL\WpfApplication2\WpfApplication2\DisplayWindow..xaml.cs:line 79
at WpfApplication2.MainWindow..ctor() in c:\Users\user\Desktop\wpf\KinectREAL\WpfApplication2\WpfApplication2\MainWindow.xaml.cs:line 45
InnerException: