Пример #1
0
        protected void CreatePicture()
        {
            int    width           = (((int)this.Width.Value) * this.resolutiondpi) / 0x60;
            int    height          = (((int)this.Height.Value) * this.resolutiondpi) / 0x60;
            string encodebinarystr = "";
            string str             = this.text;
            string checkStr        = "";

            if (this.barType == BarType.PDF417)
            {
                str = this.text;
            }
            if (this.barType == BarType.PDF417)
            {
                encodebinarystr = this.GetPDF417Str(0x60, str);
            }
            else if (this.barType == BarType.DataMatrix)
            {
                encodebinarystr = this.GetDataMatrixStr(str);
            }
            else if (this.barType < BarType.PDF417)
            {
                LinearEncoder encoder = new LinearEncoder();
                encoder.narrowratio = this.ratio;
                if (((this.barType != BarType.Code39) && (this.barType != BarType.Code25)) && ((this.barType != BarType.I25) && (this.barType != BarType.Codabar)))
                {
                    this.addcheckdigit = true;
                }
                string demoStr  = null;
                string drawText = null;
                encodebinarystr = encoder.Encoding((int)this.barType, ref str, this.addcheckdigit, out checkStr, out demoStr, out drawText);
            }
            this.picture = new Bitmap(width, height);
            this.picture.SetResolution((float)this.resolutiondpi, (float)this.resolutiondpi);
            Graphics g = Graphics.FromImage(this.picture);

            if (this.barType == BarType.PDF417)
            {
                PDF417Image image = new PDF417Image();
                this.InitPDF417Img(ref this.picture, ref image, encodebinarystr, this.resolutiondpi, width, height);
                image.DrawPDF417(ref g);
            }
            else if (this.barType == BarType.DataMatrix)
            {
                DataMatrixImage datamatriximg = new DataMatrixImage();
                this.InitDataMatrixImg(ref this.picture, ref datamatriximg, encodebinarystr, this.resolutiondpi, width, height);
                datamatriximg.DrawDataMatrix(ref g);
            }
            else if (this.barType < BarType.PDF417)
            {
                LinearImage image3 = new LinearImage();
                this.InitLinearImg(ref this.picture, ref image3, checkStr, str, encodebinarystr, this.resolutiondpi, width, height);
                image3.DrawLinear(ref g);
            }
            g.Dispose();
        }
 /// <summary>
 /// Creates a new PixelBufferDescriptor referencing a compressed image in main memory.
 /// </summary>
 /// <param name="linearImage">LinearImage to use for data.</param>
 /// <param name="format">Compressed format of the image.</param>
 /// <param name="imageSize">Compressed size of the image.</param>
 public PixelBufferDescriptor(
     LinearImage linearImage,
     CompressedPixelDataType format, int imageSize)
 {
     LinearImage      = linearImage;
     ImageSize        = imageSize;
     CompressedFormat = format;
     Type             = PixelDataType.Compressed;
     Alignment        = 1;
 }
 /// <summary>
 /// Creates a new PixelBufferDescriptor referencing an image in main memory.
 /// </summary>
 /// <param name="linearImage">LinearImage to use for data.</param>
 /// <param name="format">Format of the image pixels.</param>
 /// <param name="type">Type of the image pixels.</param>
 public PixelBufferDescriptor(
     LinearImage linearImage,
     PixelDataFormat format, PixelDataType type)
 {
     LinearImage = linearImage;
     Stride      = 0;
     Format      = format;
     Type        = type;
     Alignment   = 1;
 }
        /// <summary>
        /// Creates a new PixelBufferDescriptor referencing an image in main memory.
        /// </summary>
        /// <param name="linearImage">LinearImage to use for data.</param>
        /// <param name="format">Format of the image pixels.</param>
        /// <param name="type">Type of the image pixels.</param>
        /// <param name="alignment">Alignment in bytes of pixel rows.</param>
        /// <param name="left">Left coordinate in pixels.</param>
        /// <param name="top">Top coordinate in pixels.</param>
        /// <param name="stride">Stride of a row in pixels.</param>
        public PixelBufferDescriptor(
            LinearImage linearImage,
            PixelDataFormat format, PixelDataType type, int alignment,
            int left, int top, int stride)
        {
            LinearImage = linearImage;
            Format      = format;
            Type        = type;

            Left      = left;
            Top       = top;
            Stride    = stride;
            Alignment = alignment;
        }
Пример #5
0
        private Bitmap GetLinearBitmap()
        {
            string        checkStr;
            string        demoStr;
            string        drawText;
            LinearEncoder encoder = new LinearEncoder();

            encoder.narrowratio = this.ratio;
            if (((this.symbology != 0) && (this.symbology != 10)) && ((this.symbology != 11) && (this.symbology != 13)))
            {
                this.addcheckdigit = true;
            }
            string      text4  = encoder.Encoding(this.symbology, ref this.texttoencode, this.addcheckdigit, out checkStr, out demoStr, out drawText);
            Bitmap      bitmap = new Bitmap(this.symbolwidth, this.symbolheight);
            Graphics    g      = Graphics.FromImage(bitmap);
            LinearImage image  = new LinearImage();

            image.encodebinarystr           = text4;
            image.encodestr                 = this.texttoencode;
            image.symbolwidth               = this.symbolwidth;
            image.symbolheight              = this.symbolheight;
            image.narrowbarwidth            = this.narrowbarwidth;
            image.barheight                 = this.barheight;
            image.leftmargin                = this.leftmargin;
            image.topmargin                 = this.topmargin;
            image.textmargin                = this.textmargin;
            image.forecolor                 = this.forecolor;
            image.backcolor                 = this.backcolor;
            image.symbology                 = this.symbology;
            image.checkstr                  = checkStr;
            image.addcheckdigittotext       = this.addcheckdigittotext;
            image.showtext                  = this.showtext;
            image.txtFont                   = new Font(this.fontname, (float)this.fontsize);
            image.topcomment                = this.topcomment;
            image.bottomcomment             = this.bottomcomment;
            image.topcommenttopmargin       = this.topcommenttopmargin;
            image.topcommentleftmargin      = this.topcommentleftmargin;
            image.bottomcommentleftmargin   = this.bottomcommentleftmargin;
            image.bottomcommentbottommargin = this.bottomcommentbottommargin;
            image.bearerbars                = this.bearerbars;
            image.texttostretch             = this.texttostretch;
            image.resolutiondpi             = 0x60;
            image.textalignment             = this.textalignment;
            image.DrawLinear(ref g);
            g.Dispose();
            return(bitmap);
        }
Пример #6
0
        private static Texture CreateSplatTexture(Engine engine)
        {
            // To generate a Gaussian splat, create a single-channel 3x3 texture with a bright pixel in
            // its center, then magnify it using a Gaussian filter kernel.
            var splat = new LinearImage(3, 3, 1);

            splat.SetPixelData(1, 1, 0.25f);
            splat = ImageSampler.ResampleImage(splat, TEXTURE_SIZE, TEXTURE_SIZE, ImageSamplerFilter.GaussianScalars);

            var buffer = new PixelBufferDescriptor(splat, PixelDataFormat.R, PixelDataType.Float);

            var texture = TextureBuilder.Create()
                          .WithWidth(TEXTURE_SIZE)
                          .WithHeight(TEXTURE_SIZE)
                          .WithLevels(1)
                          .WithSampler(TextureSamplerType.Texture2d)
                          .WithFormat(TextureFormat.R32F)
                          .Build(engine);

            texture.SetImage(engine, 0, buffer);

            return(texture);
        }
Пример #7
0
        private void InitLinearImg(ref Bitmap outputBitmap, ref LinearImage b1, string checkStr, string str, string encodebinarystr, int resolutiondpi, int width, int height)
        {
            b1.encodestr       = str;
            b1.symbolwidth     = (((((int)this.Width.Value) * 0x60) / 0x3e8) * resolutiondpi) / 0x60;
            b1.symbolheight    = (((int)this.Height.Value) * resolutiondpi) / 0x60;
            b1.encodebinarystr = encodebinarystr;
            if (((int)Math.Round((double)((this.narrowbarwidth * resolutiondpi) / 1000))) >= 1)
            {
                b1.narrowbarwidth = (int)Math.Round((double)((this.narrowbarwidth * resolutiondpi) / 1000));
            }
            else
            {
                b1.narrowbarwidth = 1;
            }
            b1.barheight                 = (int)Math.Round((double)((this.barheight * resolutiondpi) / 1000));
            b1.leftmargin                = (int)Math.Round((double)((this.leftmargin * resolutiondpi) / 1000));
            b1.topmargin                 = (int)Math.Round((double)((this.topmargin * resolutiondpi) / 1000));
            b1.textmargin                = (int)Math.Round((double)((this.textmargin * resolutiondpi) / 10000));
            b1.topcommentleftmargin      = (int)Math.Round((double)((this.topcommentleftmargin * resolutiondpi) / 1000));
            b1.topcommenttopmargin       = (int)Math.Round((double)((this.topcommenttopmargin * resolutiondpi) / 1000));
            b1.bottomcommentleftmargin   = (int)Math.Round((double)((this.bottomcommentleftmargin * resolutiondpi) / 10000));
            b1.bottomcommentbottommargin = (int)Math.Round((double)((this.bottomcommentbottommargin * resolutiondpi) / 1000));
            b1.forecolor                 = this.ForeColor;
            b1.backcolor                 = this.BackColor;
            b1.symbology                 = (int)this.barType;
            b1.checkstr            = checkStr;
            b1.addcheckdigittotext = this.addcheckdigittotext;
            b1.showtext            = this.showtext;

            FontStyle style = FontStyle.Regular;

            style     |= this.Font.Bold ? FontStyle.Bold : 0;
            style     |= this.Font.Italic ? FontStyle.Italic : 0;
            style     |= this.Font.Strikeout ? FontStyle.Strikeout : 0;
            style     |= this.Font.Underline ? FontStyle.Underline : 0;
            b1.txtFont = new Font(this.Font.Name, (float)this.Font.Size.Unit.Value, style);


            b1.topcomment    = this.topcomment;
            b1.bottomcomment = this.bottomcomment;
            b1.resolutiondpi = resolutiondpi;
            b1.texttostretch = this.texttostretch;
            b1.bearerbars    = this.bearerbars;
            b1.textalignment = (int)this.textalignment;
            switch (this.rotation)
            {
            case Rotation.Clockwise_Zero_Degree:
                break;

            case Rotation.Clockwise_90_Degree:
                outputBitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
                return;

            case Rotation.Clockwise_180_Degree:
                outputBitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);
                return;

            case Rotation.Clockwise_270_Degree:
                outputBitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);
                break;

            default:
                return;
            }
        }
 public static LinearImage ResampleImage(LinearImage source, int width, int height, ImageSamplerFilter filter)
 {
     return(LinearImage.GetOrCreateCache(
                Native.Image.ImageSampler.ResampleImage(source.NativePtr, width, height, (int)filter)
                ));
 }