Example #1
0
        private void buttonReadFromResults_Click(object sender, EventArgs e)
        {
            if (results != null)
            {
                SetStatus("processing");
                textBoxBarcodes.Text = "";
                int position = 0;
                foreach (Rectangle rectangle in results)
                {
                    Bitmap labelImage = new Bitmap(rectangle.Width, rectangle.Height);
                    Graphics labelGraphics = Graphics.FromImage(labelImage);
                    labelGraphics.DrawImage(sourceImage, new Rectangle(0, 0, rectangle.Width, rectangle.Height), rectangle, GraphicsUnit.Pixel);
                    labelGraphics.Dispose();

                    Bitmap testFilters = new Bitmap(labelImage);
                    Bitmap testFiltersProcess = new Bitmap(labelImage);
                    unsafe
                    {
                        BitmapData labelData = testFilters.LockBits(new Rectangle(0, 0, testFilters.Width, testFilters.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
                        BitmapData labelDataProcess = testFiltersProcess.LockBits(new Rectangle(0, 0, testFiltersProcess.Width, testFiltersProcess.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
                        uint* pointerSource = (uint*)labelData.Scan0;
                        uint* pointerProcess = (uint*)labelDataProcess.Scan0;

                        GreyscaleFilter grey = new GreyscaleFilter();
                        grey.Process(pointerSource, pointerProcess, labelImage.Size);

                        testFiltersProcess.Save(@"C:\Temp\labels\label_" + position + ".png");

                        testFiltersProcess.UnlockBits(labelDataProcess);
                        testFilters.UnlockBits(labelData);
                    }

                    unsafe
                    {
                        BitmapData data = labelImage.LockBits(new Rectangle(0, 0, labelImage.Width, labelImage.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
                        uint* pointer = (uint*)data.Scan0;

                        BarcodeReader reader = new BarcodeReader();
                        textBoxBarcodes.Text += reader.ReadCode39(pointer, labelImage.Size);
                        textBoxBarcodes.Text += "\r\n";

                        labelImage.UnlockBits(data);
                    }

                    position++;

                }
                SetStatus("idle");
            }
        }
Example #2
0
        private unsafe void button1_Click(object sender, EventArgs e)
        {
            BitmapData data = originalImage.LockBits(new Rectangle(0, 0, originalImage.Width, originalImage.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
            uint* pointer = (uint*)data.Scan0;

            textBoxBarcodes.Text = "";

            BarcodeReader reader = new BarcodeReader();
            textBoxBarcodes.Text += reader.ReadCode39(pointer, originalImage.Size);
            textBoxBarcodes.Text += "\n";

            originalImage.UnlockBits(data);
        }