Jopsen.dk - A Personal website
Warning: Invalid argument supplied for foreach() in /home/jopjopsen/jopsen.dk/blog/wp-content/themes/jopsen.dk/header.php on line 48


December 30, 2009
ZBar bindings for C#
Filed under: Computer,English,zbar-sharp by Jonas Finnemann Jensen at 06:58

gtkzbar-sharp-exampleAs part of the food management system my group made this semester, we wrote bindings for ZBar and based on those a bar scanning widget for Gtk#. Anyway, I figured it might be useful somebody else, so I’ve been using a few days cleaning up the ZBar bindings, extracting the Gtk# widget from our UI-mess and writing a simple example of how to use it.

The result is bindings for a subset of ZBar and a Gtk# bar scanning widget. I don’t intend to maintain the source, but if you find any bugs etc. or wish to start a project for the bindings, please leave a comment…

The example application using the bar code scanning widget can be seen on to right. Note: this was a really lousy webcam :) . The check-mark appears when a bar code have been recognized and then fades away.

In Foodolini we used HAL to detect webcams as they were plugged, however, having heard that Ubuntu will be deprecating HAL, I didn’t care to clean up the source for this feature. If you interested it can be found in the source for Foodolini. And if anybody should happen to know how to detect webcams, distro independently, without HAL, please leave a comment…

9 Comments »

  1. [...] the time or the reason… Anyway, as I discovered a minor bug in the zbar-sharp bindings I recently released… I figured this might just be the kind of project I could push to github, and either forget [...]

    Pingback by Jopsen.dk/blog — January 31, 2010 @ 08:02

  2. Hi Jopsen,
    This is very useful. Do you know how to build ZBar in Visual Studio? I could not find any information. The main reason that I am asking is that I want to make a Pocket PC program.

    Best regards,
    Alper

    Comment by Alper Yaman — May 11, 2010 @ 05:17

  3. zbar no… but just use the binaries the project ship… Or ask them…

    zbar-sharp can probably be opened directly in VS… Haven’t tried though…
    You can download the source from: http://github.com/jopsen/zbar-sharp

    Comment by Jonas Finnemann Jensen — May 11, 2010 @ 05:32

  4. Hey

    I’ve just spend 30mins or so trying to use your bindings in windows / visual studio but am yet to be successful.

    Any help you can give? example C# windows code perhaps?

    Thanks
    NB: Im trying to use your bindings to enable me to run ZBAR with C#, and to make an app to achieve something similar to that of yours above, ie shows web cam picture, detects barcode and then use that in the app. (bascially make the output of ZBAR usable in a c# proggy)

    Comment by birdi3 — July 9, 2010 @ 07:09

  5. The example given should work with VS, but requires gtk-sharp, if you don’t want to play install that I’ve pushed a new example (bmp-scanner) to github.com/jopsen/zbar-sharp.

    The bmp-scanner example is hard coded to the image it distributed with… But it works and shows how zbar-sharp can also be used.

    Remember to link against zbar-sharp in your project file, and put libzbar-sharp.dll and libzbar.dll next to the binary when running it.

    Note the binary libzbar.dll (the one from zbar.sf.net) may be named zbar.dll or libzbar-1.dll or something, but it needs to be renamed to libzbar.dll

    Let me know if have any problems building it… I don’t have time to test it on a Windows VM right now…

    Comment by Jonas Finnemann Jensen — July 9, 2010 @ 11:01

  6. Thanks for your reply!

    I had a play further yesterday (before reading your comment) and only got as far as hitting an error such as ‘Unable to load DLL libzbar”, despite having it renamed and in line with the binary, (ie in the debug folder, as well as in other locations as I tried to test it), but then managed to get this working by moving in the other dll’s from ZBAR (..really should have done that first time round)

    With this in mind and your help above, I have since been able to get your example working! Huge thanks for the swift reply and good example, hopefully it will be very useful for others! Next challenge is to get it reading directly from the cam in Windows. Wish me luck and I hopefully wont be back too soon! :P

    Thanks Again

    Comment by birdi3 — July 10, 2010 @ 07:43

  7. Any advice how to discover the PixelFormat of a bmp image and how to discover the video device string?

    Comment by Varro — July 28, 2010 @ 07:58

  8. If you’re on Windows:
    The video capture in zbar on Windows uses Video For Windows. A very old legacy API, you may wish to write your own capturing code that uses whatever is hot in Windows, probably DirectShow. And give the captured images to zbar…
    I have an example where I read a barcode in a BMP:
    http://github.com/jopsen/zbar-sharp/tree/master/example/bmp-scanner/

    If you write such code please share…

    If you’re on Linux, you can get the video device string from HAL. I did this using dbus, the code is available at http://jopsen.dk/blog/2009/12/foodolini-a-food-management-system/
    However, HAL is being deprecated… So it’s probably better to get it elsewhere. If you find out how, let me know…

    I don’t know how to discover the PixelFormat, if you’re talking about bmp from files, I suggest you find a bmp reader/parser or read the specification…

    - Best of luck…

    Comment by Jonas Finnemann Jensen — July 28, 2010 @ 14:50

  9. Thank you for the fast reply.
    Currently i’m working on windows system, trying to create a piece of code which makes the bmp and jpeg scanning (like bmp-scanner you made).
    Thank you for the advice and thank you for your library.
    Regards.

    Comment by Varro — August 1, 2010 @ 03:09

Leave a comment