I am creating a WPF application. I used a barcode library to generate barcode of each employee ID. But when I try to assign barcode image to Image Control then it shows following error:
cannot implicitly convert type system.drawing.image to system.windows.controls.image
Here is my code:
我正在创建一个WPF应用程序。我使用条形码库生成每个员工ID的条形码。但是当我尝试将条形码图像分配给Image Control时,它会显示以下错误:无法将类型system.drawing.image隐式转换为system.windows.controls.image这是我的代码:
public partial class Card : Window
{
private PrintDialog dialog;
Image myimg;
public Card(String a, String b, String c, String d, String e, String f, String g, String h, String i)
{
InitializeComponent();
myimg = Code128Rendering.MakeBarcodeImage(h, 2, true);
image2 = myimg;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
dialog = new PrintDialog();
dialog.PrintVisual(canvas1, "Employee Card");
}
}
Please help me out.
请帮帮我。
1 个解决方案
#1
1
The error should be pretty obvious, the field myImg
or image2
are of type system.windows.controls.image
, while the method creates a system.drawing.image
.
错误应该非常明显,字段myImg或image2的类型为system.windows.controls.image,而该方法创建了一个system.drawing.image。
Without knowing the purpose of the field it's hard to say what you should do, but if you just want a reference you need to qualify the type or change your using statements to not include the controls namespace.
如果不知道该字段的用途,很难说你应该做什么,但如果你只想要一个引用,你需要限定类型或更改你的using语句不包括controls名称空间。
e.g. for qualified reference:
例如供参考:
System.Drawing.Image myImg;
If image2
caused the error you probably want to convert the drawing.image
to an ImageSource
of some kind (it's the base WPF image type) and assign it to the image2.
Source
instead. I am sure that there is a question about this convertion on SO somewhere if you do not know how to do that.
如果image2导致错误,您可能希望将drawing.image转换为某种类型的ImageSource(它是基本WPF图像类型),并将其分配给image2.Source。如果你不知道怎么做,我确信在某个地方有一个关于这种转换的问题。
#1
1
The error should be pretty obvious, the field myImg
or image2
are of type system.windows.controls.image
, while the method creates a system.drawing.image
.
错误应该非常明显,字段myImg或image2的类型为system.windows.controls.image,而该方法创建了一个system.drawing.image。
Without knowing the purpose of the field it's hard to say what you should do, but if you just want a reference you need to qualify the type or change your using statements to not include the controls namespace.
如果不知道该字段的用途,很难说你应该做什么,但如果你只想要一个引用,你需要限定类型或更改你的using语句不包括controls名称空间。
e.g. for qualified reference:
例如供参考:
System.Drawing.Image myImg;
If image2
caused the error you probably want to convert the drawing.image
to an ImageSource
of some kind (it's the base WPF image type) and assign it to the image2.
Source
instead. I am sure that there is a question about this convertion on SO somewhere if you do not know how to do that.
如果image2导致错误,您可能希望将drawing.image转换为某种类型的ImageSource(它是基本WPF图像类型),并将其分配给image2.Source。如果你不知道怎么做,我确信在某个地方有一个关于这种转换的问题。