コード例 #1
0
        public void DrawImage(ref Bitmap bm, string code39)
        {
            com.google.zxing.oned.Code39Writer writer = new com.google.zxing.oned.Code39Writer();
            com.google.zxing.common.ByteMatrix matrix;

            Graphics g = null;

            g = Graphics.FromImage(bm);
            float mag = PixelConversions.GetMagnification(g, bm.Width, bm.Height,
                                                          OptimalHeight, OptimalWidth);

            int barHeight = PixelConversions.PixelXFromMm(g, OptimalHeight * mag);
            int barWidth  = PixelConversions.PixelYFromMm(g, OptimalWidth * mag);

            matrix = writer.encode(code39, com.google.zxing.BarcodeFormat.CODE_39,
                                   barWidth, barHeight, null);


            bm = new Bitmap(barWidth, barHeight);
            Color Color = Color.FromArgb(0, 0, 0);

            for (int y = 0; y < matrix.Height; ++y)
            {
                for (int x = 0; x < matrix.Width; ++x)
                {
                    Color pixelColor = bm.GetPixel(x, y);

                    //Find the colour of the dot
                    if (matrix.get_Renamed(x, y) == -1)
                    {
                        bm.SetPixel(x, y, Color.White);
                    }
                    else
                    {
                        bm.SetPixel(x, y, Color.Black);
                    }
                }
            }
        }
コード例 #2
0
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public com.google.zxing.common.BitMatrix encode(String contents, BarcodeFormat format, int width, int height, java.util.Map<EncodeHintType,?> hints) throws WriterException
 public BitMatrix encode(string contents, BarcodeFormat format, int width, int height, IDictionary<EncodeHintType, object> hints)
 {
     Writer writer;
     switch (format)
     {
       case com.google.zxing.BarcodeFormat.EAN_8:
     writer = new EAN8Writer();
     break;
       case com.google.zxing.BarcodeFormat.EAN_13:
     writer = new EAN13Writer();
     break;
       case com.google.zxing.BarcodeFormat.UPC_A:
     writer = new UPCAWriter();
     break;
       case com.google.zxing.BarcodeFormat.QR_CODE:
     writer = new QRCodeWriter();
     break;
       case com.google.zxing.BarcodeFormat.CODE_39:
     writer = new Code39Writer();
     break;
       case com.google.zxing.BarcodeFormat.CODE_128:
     writer = new Code128Writer();
     break;
       case com.google.zxing.BarcodeFormat.ITF:
     writer = new ITFWriter();
     break;
       case com.google.zxing.BarcodeFormat.PDF_417:
     writer = new PDF417Writer();
     break;
       case com.google.zxing.BarcodeFormat.CODABAR:
     writer = new CodaBarWriter();
     break;
       default:
     throw new System.ArgumentException("No encoder available for format " + format);
     }
     return writer.encode(contents, format, width, height, hints);
 }
コード例 #3
0
ファイル: BarCode39.cs プロジェクト: hardsoft/My-FyiReporting
        public void DrawImage(ref Bitmap bm, string code39)
        {
            com.google.zxing.oned.Code39Writer writer = new com.google.zxing.oned.Code39Writer();
            com.google.zxing.common.ByteMatrix matrix;

            Graphics g = null;
            g = Graphics.FromImage(bm);
            float mag = PixelConversions.GetMagnification(g, bm.Width, bm.Height,
                OptimalHeight, OptimalWidth);

            int barHeight = PixelConversions.PixelXFromMm(g, OptimalHeight * mag);
            int barWidth = PixelConversions.PixelYFromMm(g, OptimalWidth * mag);

            matrix = writer.encode(code39, com.google.zxing.BarcodeFormat.CODE_39,
                barWidth, barHeight, null);

            bm = new Bitmap(barWidth, barHeight);
            Color Color = Color.FromArgb(0, 0, 0);

            for (int y = 0; y < matrix.Height; ++y)
            {
                for (int x = 0; x < matrix.Width; ++x)
                {
                    Color pixelColor = bm.GetPixel(x, y);

                    //Find the colour of the dot
                    if (matrix.get_Renamed(x, y) == -1)
                    {
                        bm.SetPixel(x, y, Color.White);
                    }
                    else
                    {
                        bm.SetPixel(x, y, Color.Black);
                    }
                }
            }
        }