Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello,

I am using a third party dll for generating barcode in my application. For that the code I am using is
C#
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.
Posted
Updated 10-Nov-13 8:58am
v3
Comments
ridoy 10-Nov-13 15:01pm    
So what, use that winform controls inside your wpf code.

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: http://msdn.microsoft.com/en-us/library/system.windows.media.imagesource%28v=vs.110%29.aspx[^]), 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:
http://stackoverflow.com/questions/2440267/interopbitmap-to-bitmapimage[^].

Of find out another barcode library working with WPF.

—SA
 
Share this answer
 
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.

C#
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();

bi.BeginInit();

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;

bi.EndInit();

imgMfgNameBarcode.Source = bi;
 
Share this answer
 
v3
Comments
Member 15489619 9-Apr-22 4:06am    
thanks bro you solved my problem 0_^

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900