Azeem
Azeem

Reputation: 2924

cannot implicitly convert type system.drawing.image to system.windows.controls.image

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:

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.

Upvotes: 1

Views: 7997

Answers (1)

brunnerh
brunnerh

Reputation: 185072

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.

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.

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.

Upvotes: 1

Related Questions