Пример #1
0
        public byte[] GetCodeContent(BarcodeInfo info, int sizeFactor, ImageFormat imageFormat)
        {
            BarcodeBitmap bmp = new BarcodeBitmap(info.Width, info.Width, sizeFactor);

            Color black = Color.Black;
            Color white = Color.White;

            for (int i = 0; i < info.Width; i++)
            {
                for (int j = 0; j < info.Width; j++)
                {
                    if (info.Data[j + i * info.Width] == 1)
                    {
                        bmp.SetPixel(j, i, black);
                    }
                    else
                    {
                        bmp.SetPixel(j, i, white);
                    }
                }
            }
            using (MemoryStream stream = new MemoryStream())
            {
                bmp.GetBitmap().Save(stream, imageFormat);
                byte[] content = new byte[stream.Length];
                return(stream.GetBuffer());
            }
        }
Пример #2
0
        public void SaveImage(BarcodeInfo info, string filename, int sizeFactor)
        {
            _imageFileName = filename;
            BarcodeBitmap bmp = new BarcodeBitmap(info.Width, info.Width, sizeFactor);

            Color black = Color.Black;
            Color white = Color.White;

            for (int i = 0; i < info.Width; i++)
            {
                for (int j = 0; j < info.Width; j++)
                {
                    if (info.Data[j + i * info.Width] == 1)
                    {
                        bmp.SetPixel(j, i, black);
                    }
                    else
                    {
                        bmp.SetPixel(j, i, white);
                    }
                }
            }

            bmp.Save(_imageFileName, ImageFormat.Bmp);
        }