A blog by Jonas Finnemann Jensen

March 19, 2011
Version 0.10 of zbar-sharp is out…
Filed under: Computer,English,zbar-sharp by jonasfj at 9:50 am

Being slightly bored with school work I decided to take day off and work on zbar-sharp, and a few minutes ago I tagged a new release of zbar-sharp. These improvements have been underway for quite a while, and many of them have been available in the repository on github for a long time. And if you plan to use zbar-sharp I’ll recommend that you checkout the git repository once in a while.

The highlights of this release are:

  • ZBar.Image: Constructor for loading from System.Drawing.Image (e.g. Bitmap import)
  • ZBar.Image: Fix for nasty memory management issue in ZBar.Image.Data
  • ZBar.Image: Convenience function for FourCC codes.
  • ZBar.Symbol: Support for QR-codes (thanks to ZBar)
  • GtkZBar.Scanner: Support for rotation (Special thanks to Patrick McEvoy)
  • ZBar: Version by (Special thanks to Brandon McCaig)
  • Tests: Unit tests to test zbar-sharp and ZBar.
  • Improved and reorganized examples…

In particular support for initializing ZBar.Image from an instance of System.Drawing.Image is very nice. Notice that System.Drawing.Bitmap is a subclass of System.Drawing.Image, so this constructor allows you to load images from files into a ZBar.Image that can be scanned.

However, this feature would have been fairly unstable without a fix for the memory management issue in ZBar.Image.Data, which previously caused applications to crash at random. A thanks to the nameless commentor by the name thedarkking, who’s comment finally gave me a clue as to where the bug was.

By the way, if you have any comments or questions don’t be afraid to leave a comment.You’re also welcome to use the issue reporting system at github to report bugs or feature requests.If you wish to contribute, just fork the project on github and push your code.


  1. Hi there.. i would to like to use zbar-sharp in my application.. i manage to scan 1D barcode.. but.. zbar-sharp 0.10 still cant scan qr-code.. there is qrcode support in 0.10 right? i use your sample application called “bmp-scanner.exe” to scan barcode.bmp that contain qr code.. qr code generated from

    Comment by doyok — June 23, 2011 @ 7:06 pm

  2. hi, i manage to read qrcode now… this is interesting link to read

    someone mention that if you are converting bitmap image using memorystream.. memorystream “won’t produce the exact copy of the bitmap bits from the memory”. So.. i convert Bitmap to byte[] using other method 1 listed there.. then only send the byte[] to zbar.scan(). and the result is… qrcode can be read by zbarsharp thx.

    Comment by doyok — June 23, 2011 @ 8:32 pm

  3. I’m sure memory stream conversation is also slower than a direct copy. Also it quite stupid not to have a constructor overload for System.Drawing.Bitmap, as no drawing/conversation except a single copy is needed for these.

    I’ve added an issue for this to the wishlist:

    By the way, if you end up using zbar-sharp for any cool applications please do drop a link in the comments 🙂

    Comment by Jonas Finnemann Jensen — June 24, 2011 @ 3:52 am

  4. thx for the response.. i don’t mind with slow image conversion.. as long as it can read the symbol… but if you can make it faster.. then its a bonus.. 🙂 thx..

    Comment by doyok — June 25, 2011 @ 2:07 am

  5. Hi
    I use libzbar-cil.dll in C# project。
    System.Drawing.Image oBitmap = System.Drawing.Image.FromFile(“E:\ZbarTest\images\img05379.jpg”);
    ImageScanner oImageScanner = new ImageScanner();
    List symbols = oImageScanner.Scan(oBitmap);

    scanning a jpg file with barcode,Scanning image returning 0
    if use zbarimg.exe, no problem。
    Could you give me advices.
    By the way, I have to install Imagemagick?


    Comment by tyo — August 8, 2011 @ 4:11 am

  6. You don’t have to install ImageMagick.
    But zbarimg.exe uses ImageMagick for grey scale conversion, where as zbar-sharp uses a builtin algorithm from zbar.

    Sometimes the grey scale conversion algorithm from ImageMagick is better, but I’ve also found cases where the builtin algorithm is best…
    So this issue needs further investigation.

    Anyway, to answer your question, zbar-sharp and zbarimg.exe does not use the same grey scale conversion algorithm. But you can do your own grey scale conversion for zbar-sharp. If you do this, please share it 🙂

    Comment by Jonas Finnemann Jensen — August 12, 2011 @ 7:35 pm

  7. Hello, Jonas!

    Can you please help me – i try to use your example project – image-scanner, but i can’t succeed:
    Unable to load DLL ‘libzbar’: The specified module could not be found. (Exception from HRESULT: 0x8007007E)

    I did put libzbar in a folder with application (it all goes in one folder), but i still got the same mistake, i took libzar from last zbar release – the file named ‘libzbar-0.dll’ i renamed it, but no success.

    Thanks in advance.

    Comment by ups — September 16, 2011 @ 2:25 am

  8. @ups,
    you need to have the libzbar.dll in the same folder as zbar-sharp.dll and your_application.exe.
    I would guess that your problem is that you put the libzbar.dll in the folder where the sources are, and not with the binary (your_application.exe).
    Also you should copy all the dlls distributed with zbar into this folder…

    Comment by Jonas Finnemann Jensen — September 17, 2011 @ 2:39 am

  9. Hello Jonas!

    I’m trying to make the sample work, but can’t 🙁 Hope you can help me.

    I’m getting this error:

    Message=An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
    at ZBar.ImageScanner.zbar_image_scanner_create()
    at ZBar.ImageScanner..ctor() in D:...jopsen-zbar-sharp-8c608a2libzbar-cilImageScanner.cs:line 42
    at Example.ImageScanner.SimpleImageScanner.Main(String[] args) in D:...jopsen-zbar-sharp-8c608a2exampleimage-scannerimage-scanner.cs:line 52

    I’ve copied all the DLLs from the Zbar lib and renamed libzbar-0.dll to libzbar.dll.

    You mention zbar-sharp.dll, but the code generates a libzbar-cil.dll. I’m little confused there. Did I need another dll?

    Comment by Eduardo — September 27, 2011 @ 11:07 am

  10. Running VS2010 in Win7 64 bits

    Comment by Eduardo — September 27, 2011 @ 11:08 am

  11. Nevermind! Used ZXing C# port and worked like a charm.

    Comment by Eduardo — September 27, 2011 @ 2:05 pm

  12. Hey Jonas! Great work at first!

    Would like to use zBar in my new program im writing at the moment. I took the libzbar-cil.dll and linked it with my program and build the hole project, but when i started it, it gives me a fail message.
    Then I found the info, to put all the dlls from the zbar application into my debug bin folder and now there is a PInkoveStackImbalance failure.

    Please help! Here my code in

    Dim image2 As System.Drawing.Image
    Dim sym As ZBar.Symbol
    Dim List As List(Of ZBar.Symbol)

    image2 = New Bitmap(TextBox1.Text)
    Catch ex As Exception
    End Try
    PictureBox1.ImageLocation = TextBox1.Text
    Label3.Text = TextBox1.Text

    Dim scanner As New ZBar.ImageScanner
    ‘scanner.Cache = False
    List = scanner.Scan(image2)

    For Each sym In List

    Comment by David — December 9, 2011 @ 12:59 am

  13. Okay got a new hint. The Programm starts but then it wants to find the file image.cs. But I thought this one should be in the dll file already or not?
    My steps were:
    – Took your Solution file and compiled it with VisStud C# (I deleted the gtk files and the tests one, because they caused error, but I think thats okay because I will not use them)
    – Imported the libzbar-cil.dll into my project, copied the .dll files from zbar into my binary folder, and compiled it.
    – When I start die programm, it crashes because of PInvoke StackImbalance failure.

    Got any kind of knowledge about that?

    Comment by David — December 9, 2011 @ 3:45 am

  14. I haven’t run into PInvokeStackImbalance failure before.
    If I find some time this weekend, I’ll send you an example that I managed to get running 🙂

    Comment by Jonas Finnemann Jensen — December 9, 2011 @ 4:01 am

  15. that would be great! I think im doing something wrong because VisStud shows that the source of the failure is the missing file image.cs..

    Comment by David — December 9, 2011 @ 4:13 am

  16. Some more Information:

    Eine Ausnahme (erste Chance) des Typs “System.DllNotFoundException” ist in libzbar-cil.dll aufgetreten.
    Eine Ausnahme (erste Chance) des Typs “System.DllNotFoundException” ist in libzbar-cil.dll aufgetreten.
    Eine Ausnahme (erste Chance) des Typs “System.DllNotFoundException” ist in libzbar-cil.dll aufgetreten.

    Comment by David — December 9, 2011 @ 5:24 am

  17. Did you rename libzbar-0.dll to libzbar.dll, if not that’s your issue.
    libzbar-cil.dll assumes the zbar dll is called libzbar.dll and libzbar-0.dll

    Comment by Jonas Finnemann Jensen — December 11, 2011 @ 12:02 pm

  18. Yes I did! Thats my problem, i thought the same and looked up in my debug folder, but I copied all files from the zbar bin folder, so it should work..

    Comment by David — December 15, 2011 @ 11:06 pm

  19. Hey Jonas, look here, i made a screenshot for you – thats the problem:

    I can go through the code, but then there is no result.

    Comment by David — December 16, 2011 @ 2:06 am

  20. Could it be, that die libzbar.dll from the WindowsInstaller Packet of Zbar is not compatible with your dll? I think the Pinvoke Failure could occur because of an wrong calling.

    Comment by David — December 16, 2011 @ 4:38 am

  21. Possible, but I don’t think zbar have been updated recently.
    Have you tried to build the image-scanner example from github?
    If you remove gtkzbar-cil and gtk-scanner projects from the solution, it should build without any complications.

    Comment by Jonas Finnemann Jensen — December 16, 2011 @ 5:28 am

  22. Yes, I did it with Visual Studio, and there were no problems. Maybe you could try building a small example in to look whether it works or not. Or maybe you know someone who made it with
    Thanks in advance for your help!

    Comment by David — December 22, 2011 @ 11:22 pm

  23. Solution for
    Unable to load DLL ‘libzbar’: The specified module could not be found.
    install zbar-0.10-setup.exe you can download

    Copy all Dll Files from C:Program FilesZBarbin
    and rename libzbar-0.dll to libzbar.dll

    without regsvr32 its will work

    Comment by kh — January 5, 2012 @ 7:56 am

  24. Interesting, my Windows (R) skills are pretty old, but I do imagine that it possible to use the library without installing it globally…

    Comment by Jonas Finnemann Jensen — January 6, 2012 @ 4:48 am

  25. @kh: Tried your Solution but there is always the same point where the debugger stops:

    /// Get/set the data associated with this image
    /// This method copies that data, using Marshal.Copy.
    public byte[] Data{
    IntPtr pData = zbar_image_get_data(this.handle);
    if(pData == IntPtr.Zero)
    throw new Exception(“Image data pointer is null!”);
    uint length = zbar_image_get_data_length(this.handle);
    byte[] data = new byte[length];
    Marshal.Copy(pData, data, 0, (int)length);
    return data;
    IntPtr data = Marshal.AllocHGlobal(value.Length);
    Marshal.Copy(value, 0, data, value.Length);
    zbar_image_set_data(this.handle, data, (uint)value.Length, Image.CleanupHandler);

    When zbar_image_set_data is called, VB gives back a PInvokeFailure. I think there is something wrong with the values given over to this function..

    Comment by David — January 13, 2012 @ 12:11 am

  26. To resolve the unable to load DLL error, you need to do the following:
    1) On 64bit systems in the Build Configuration Manager, change platform from “Any CPU” to “x86”
    2) rename libzbar-0.dll to libzbar.dll
    3) copy both libzbar.dll AND libiconv-2.dll to the folder where your EXE resides, for example: example\image-scanner\bin\x86\Debug

    Comment by Sean Neeley — April 16, 2014 @ 9:11 pm

Leave a comment