Advertisement
Guest User

How To Use ZXing C# Port

a guest
Dec 8th, 2011
3,084
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. using com.google.zxing;
  2. using com.google.zxing.client.j2se;
  3. using com.google.zxing.common;
  4.  
  5. //...
  6.  
  7. Reader reader = new MultiFormatReader();
  8. MonochromeBitmapSource image = new BufferedImageMonochromeBitmapSource(new Bitmap(Image.FromFile("barcode.jpg")),false);
  9.  
  10. Result result = reader.decode(image);
  11. string text = result.getText();
  12. sbyte[] rawbytes = result.getRawBytes();
  13. BarcodeFormat format = result.getBarcodeFormat();
  14. ResultPoint[] points = result.getResultPoints();
  15. Console.WriteLine("barcode text: {0}", text);
  16. Console.WriteLine("raw bytes: {0}", rawbytes);
  17. Console.WriteLine("format: {0}", format);
  18. Console.ReadLine();
  19.  
  20. Result result = reader.decode(image);
  21.  
  22. Result result = (Result)reader.decode(image);
  23.  
  24. MultiFormatOneDResult result = reader.decode(image);
  25.  
  26. QRCodeWriter writer = new QRCodeWriter();
  27. com.google.zxing.common.ByteMatrix matrix;
  28.  
  29. int size = 180;
  30. matrix = writer.encode("MECARD:N:Owen,Sean;ADR:76 9th Avenue, 4th Floor, New York, NY 10011;TEL:+12125551212;EMAIL:srowen@example.com;; ", BarcodeFormat.QR_CODE, size, size, null);
  31.  
  32.  
  33. Bitmap img = new Bitmap(size, size);
  34. Color Color = Color.FromArgb(0, 0, 0);
  35.  
  36. for (int y = 0; y < matrix.Height; ++y)
  37. {
  38. for (int x = 0; x < matrix.Width; ++x)
  39. {
  40. Color pixelColor = img.GetPixel(x, y);
  41.  
  42. //Find the colour of the dot
  43. if (matrix.get_Renamed(x, y) == -1)
  44. {
  45. img.SetPixel(x, y, Color.White );
  46. }
  47. else
  48. {
  49. img.SetPixel(x, y, Color.Black);
  50. }
  51. }
  52. }
  53.  
  54.  
  55. img.Save(@"c:test.bmp",ImageFormat.Bmp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement