Click here to Skip to main content
14,272,315 members
Rate this:
Please Sign up or sign in to vote.
See more:

I am using a third party dll for generating barcode in my application. For that the code I am using is
Zen.Barcode.Code39BarcodeDraw obj = Zen.Barcode.BarcodeDrawFactory.Code39WithoutChecksum;
picturebox1.image = obj.draw("123456789",100);

its perfectly working in Win Forms. But when I try to use the same dll in WPF instead of picturebox my option available is Image

But I cannot draw the barcode image to WPF image control.(There is no property to set image)

Please give your valuable suggestions.
Updated 10-Nov-13 8:58am
ridoy 10-Nov-13 15:01pm
So what, use that winform controls inside your wpf code.
Rate this:
Please Sign up or sign in to vote.

Solution 1

You don't need this equivalent, because it is not really needed even in System.Windows.Forms. This is merely a control wrapping code rendering some image. Unlike other control based on raw Windows API and windows classes, you could do it by yourself.

In API, raw windows classes are not used (except main window). There is not a problem to show any images in WPF (please see all related to this:[^]), but if your library works with System.Drawing.Image only, it cannot work with WPF images. One option is this: keep using System.Drawing.Image (it has nothing to do with System.Windows.Forms), but you will need to convert the result to WPF image. There are a couple of ways to do that:

Please see:[^].

Of find out another barcode library working with WPF.

Rate this:
Please Sign up or sign in to vote.

Solution 2

I just had the same problem and got it to work like this, using the image control (named imgMfgNameBarcode). Still testing it but seems to work.

using Zen.Barcode;

Code39BarcodeDraw barcode39 = BarcodeDrawFactory.Code39WithoutChecksum;

lblMfgName.Content = "BinOptics Corporation";

//Image we want to get the WPF Image from...
sTest = lblMfgName.Content.ToString();
System.Drawing.Image img =
barcode39.Draw(lblMfgName.Content.ToString(), 40, 2);

// ImageSource ...
BitmapImage bi = new BitmapImage();


MemoryStream ms = new MemoryStream();

// Save to a memory stream...
img.Save(ms, ImageFormat.Bmp);

// Rewind the stream...
ms.Seek(0, SeekOrigin.Begin);

// Tell the WPF image to use this stream...
bi.StreamSource = ms;


imgMfgNameBarcode.Source = bi;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100