Ejemplo n.º 1
0
        private void CheckLicenseFile()
        {
            // Make sure a license for DotImage and Advanced DocClean exist.
            try
            {
                var img = new AtalaImage();
                img.Dispose();
            }
            catch (AtalasoftLicenseException ex1)
            {
                LicenseCheckFailure("This demo requires an Atalasoft DotImage license.", ex1.Message);
                return;
            }

            if (AtalaImage.Edition != LicenseEdition.Document)
            {
                LicenseCheckFailure("This demo requires an Atalasoft DotImage Document Imaging License.",
                                    string.Format("Your current license is for '{0}'.", AtalaImage.Edition));
                return;
            }

            try
            {
                // ReSharper disable once ObjectCreationAsStatement
                // We need this line to check the license.
                new TranslatorCollection();
            }
            catch (AtalasoftLicenseException ex2)
            {
                LicenseCheckFailure("Licensing exception.", ex2.Message);
                return;
            }

            _validLicense = true;
        }
Ejemplo n.º 2
0
        private void CheckLicenseFile()
        {
            // Make sure a license for DotImage and Advanced DocClean exist.
            try
            {
                AtalaImage img = new AtalaImage();
                img.Dispose();
            }
            catch (Atalasoft.Imaging.AtalasoftLicenseException ex1)
            {
                LicenseCheckFailure("This demo requires an Atalasoft DotImage license.", ex1.Message);
                return;
            }

            if (AtalaImage.Edition != LicenseEdition.Document)
            {
                LicenseCheckFailure("This demo requires an Atalasoft DotImage Document Imaging License.", "Your current license is for '" + AtalaImage.Edition.ToString() + "'.");
                return;
            }

            try
            {
                TranslatorCollection t = new TranslatorCollection();
            }
            catch (AtalasoftLicenseException ex2)
            {
                LicenseCheckFailure("Licensing exception.", ex2.Message);
                return;
            }

            this._validLicense = true;
        }
Ejemplo n.º 3
0
        //protected override void Dispose(bool disposing)
        //{
        //    if (disposing)
        //    {
        //        if (this.device != null) this.device.Close();
        //        if (this.acquisition != null) this.acquisition.Dispose();
        //    }
        //    base.Dispose(disposing);
        //}

        #endregion

        #region Atalasoft Image/Scan Events

        private void acquisition_ImageAcquired(object sender, AcquireEventArgs e)
        {
            Bitmap bitmap = e.Image;

            switch (getCheckedMenuItemIndex(miRotation))
            {
            case 1: bitmap.RotateFlip(RotateFlipType.Rotate90FlipNone); break;

            case 2: bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone); break;

            case 3: bitmap.RotateFlip(RotateFlipType.Rotate270FlipNone); break;
            }
            int page = tViewer.Items.Count + 1;

            AtalaImage atalaImage = AtalaImage.FromBitmap(bitmap);

            ScannedImages.Add(atalaImage);

            Atalasoft.Imaging.WinControls.Thumbnail thumbnail = new Atalasoft.Imaging.WinControls.Thumbnail(atalaImage, "", "");
            thumbnail.Selected = true;

            tViewer.Items.Add(thumbnail);

            RefreshView(tViewer.Items.Count - 1);
        }
Ejemplo n.º 4
0
        private byte[] GetImageData()
        {
            if (PageOpenImageControl.WorkspaceViewer.Image == null)
            {
                return(null);
            }

            AtalaImage atalaImage = null;

            if (PageOpenImageControl.WorkspaceViewer.Image.PixelFormat == PixelFormat.Pixel32bppBgra)
            {
                atalaImage = PageOpenImageControl.WorkspaceViewer.Image;
            }
            else
            {
                atalaImage = PageOpenImageControl.WorkspaceViewer.Image.GetChangedPixelFormat(PixelFormat.Pixel32bppBgra);
            }

            byte[]       memoryBuffer = new byte[atalaImage.Width * atalaImage.Height * 4 + 1042 + 18];
            MemoryStream memoryStream = new MemoryStream(memoryBuffer);

            TgaEncoder tgaEncoder = new TgaEncoder();

            tgaEncoder.Save(memoryStream, atalaImage, null);

            return(memoryBuffer);
        }
        public ImageButtonViewModel(AtalaImage image, string path, Action <string> displayCallback)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            Image = WpfConverter.AtalaImageToBitmapSource(image);

            Path            = path ?? throw new ArgumentNullException(nameof(path));
            DisplayCallback = displayCallback ?? throw new ArgumentNullException(nameof(displayCallback));
        }
Ejemplo n.º 6
0
        // Respond to a file open
        private void OpenButton_Click(object sender, EventArgs e)
        {
            // try to locate images folder
            var imagesFolder = Application.ExecutablePath;

            // we assume we are running under the DotImage install folder
            var pos = imagesFolder.IndexOf("DotImage ", StringComparison.Ordinal);

            if (pos != -1)
            {
                imagesFolder = imagesFolder.Substring(0, imagesFolder.IndexOf(@"\", pos, StringComparison.Ordinal)) + @"\Images\Barcodes";
            }

            // use this folder as starting point
            _openFileDialog.InitialDirectory = imagesFolder;

            // Filter on the available, licensed decoders
            _openFileDialog.Filter = WinDemoHelperMethods.CreateDialogFilter(true);

            if (_openFileDialog.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            try
            {
                _tmpImg = new AtalaImage(_openFileDialog.FileName);

                // Loads the image into the viewer - applying the desired morphology if needed
                UpdateMorphology();
                //// workspaceViewer.Open(openFileDialog1.FileName);
            }
            catch
            {
                MessageBox.Show(Resources.Barcoder_OpenButton_UnableToLoad + _openFileDialog.FileName + @".");
                _imageLoaded = false;
                return;
            }

            _imageLoaded = true;

            // check if its OK start a recognize at this point
            ValidateRecognize(0, 0);
            _finalResults = null;
        }
Ejemplo n.º 7
0
        public static byte[] UploadImage(string displayMode, int x, int y, int h, int w)
        {
            string path = HttpContext.Current.Server.MapPath("~/AppContent/RenderImages/uploadPlaceholder.png");

            using (AtalaImage image = new AtalaImage(856, 500, PixelFormat.Pixel32bppBgra, Color.Transparent))
            {
                using (AtalaImage uploadImage = new AtalaImage(path))
                {
                    var g = image.GetGraphics();
                    g.DrawImage(uploadImage.ToBitmap(), new Rectangle(x, y, w, h));
                    byte[] data = null;
                    using (MemoryStream m = new MemoryStream())
                    {
                        PngEncoder encoder = new PngEncoder();
                        encoder.Save(m, image, null);
                        data = m.ToArray();
                    }
                    return(data);
                }
            }
        }
        public void ConvertToGrayScale(string sourceFile, string targetFile)
        {
            MultiFramedImageEncoder encoder = new TiffEncoder();

            using (ImageSource src = new FileSystemImageSource(sourceFile, true))
            {
                ImageCollection images = new ImageCollection();

                while (src.HasMoreImages())
                {
                    AtalaImage img = src.AcquireNext();

                    img = img.GetChangedPixelFormat(PixelFormat.Pixel8bppGrayscale);
                    images.Add(img);
                    //img.Dispose();
                }

                using (Stream s = File.Create(targetFile))
                {
                    encoder.Save(s, images, null);
                }
            }
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            // Create an empty image to start with
            const int imageSize = 500;
            var       image     = new AtalaImage(imageSize, imageSize, PixelFormat.Pixel24bppBgr, Color.White);

            // Draw a simple message on the image (using Atalasoft Red color!)
            using (var g = image.GetGraphics())
                using (var atalasoftBrush = new SolidBrush(AtalasoftRed))
                {
                    // Funny message to draw on image
                    var message = "Hello from " + ProcessBitness + " process!";
                    var font    = new Font(FontFamily.GenericSansSerif, 20);

                    // Center text string and draw it!
                    var messageSize = g.MeasureString(message, font);
                    g.DrawString(message, font, atalasoftBrush,
                                 (imageSize - messageSize.Width) / 2,
                                 (imageSize - messageSize.Height) / 2);
                }

            // Save the image into PNG file
            image.Save("hello.png", new PngEncoder(), null);
        }
Ejemplo n.º 10
0
        private void workspaceViewer1_MouseClick(object sender, MouseEventArgs e)
        {
            List<strokes> strokesForOneWord = new List<strokes>();
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                oneStroke.listPoints.Add(new Point((int)(e.X / this.workspaceViewer1.Zoom), (int)(e.Y / this.workspaceViewer1.Zoom)));
                DrawLineOnImage(Color.Red);
                toolStripStatusLabel1.Text = "开始画笔画";
                nFirstLeftClick = true;
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Right && !IsControlDown()
                && !nFirstLeftClick)
            {
                MessageBox.Show("请选择笔画");
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Right && !IsControlDown()
                && nFirstLeftClick)
            {
                //Point point = new Point(e.X, e.Y);
                // prepare to select the property
                SelectProperty property = new SelectProperty();
                property.FormClosed += property_FormClosed;
                Rectangle rec = new Rectangle(e.X, e.Y, 150, 300);
                property.Show(dockPanel1, rec);

                //contextMenuStrip1.Show(point);
                //oneStroke.strProperty = property
                toolStripStatusLabel1.Text = "正在画笔画中……";

            }
            else if (IsControlDown() && e.Button == System.Windows.Forms.MouseButtons.Right
            && !nSecondRightClick)
            {
                MessageBox.Show("请选择笔画属性");
            }
            else if (IsControlDown() && e.Button == System.Windows.Forms.MouseButtons.Right
                && nSecondRightClick)
            {
                Emgu.CV.Image<Bgr, Byte> img_lines = new Emgu.CV.Image<Bgr, byte>(this.workspaceViewer1.Image.ToBitmap());
                Emgu.CV.Image<Bgr, Byte> img = new Emgu.CV.Image<Bgr, byte>(m_fileName);
                oneHanzi.nXScrollOffset = nScrollXOffset;
                oneHanzi.nYScrollOffset = nScrollYOffset;
                //Rectangle rec = oneHanzi.getBoundingRectangle();
                Rectangle rec = new Rectangle(0, 0, img.Width, img.Height);
                img_lines.ROI = rec;
                img.ROI = rec;
                Emgu.CV.Image<Bgr, Byte> crop = new Emgu.CV.Image<Bgr, Byte>(rec.Width, rec.Height);
                Emgu.CV.Image<Bgr, Byte> crop2 = new Emgu.CV.Image<Bgr, Byte>(rec.Width, rec.Height);
                CvInvoke.cvCopy(img, crop, IntPtr.Zero);
                CvInvoke.cvCopy(img_lines, crop2, IntPtr.Zero);
                oneHanzi.wordimage = crop;
                oneHanzi.wordimageWithLines = crop2;
                oneHanzi.save(m_fileName);
                oneHanzi.clear();
                toolStripStatusLabel1.Text = "存储完毕";
                nFirstLeftClick = false;
                nSecondRightClick = false;
                if (File.Exists(".\\Temp.txt"))
                {
                    File.Delete(".\\Temp.txt");
                }
                imageBackup = (AtalaImage)this.workspaceViewer1.Image.Clone();
                //crop.Save("E:\\ww.jpg");
            }
            this.workspaceViewer1.Refresh();
        }
Ejemplo n.º 11
0
 public PixelMemoryLocker(AtalaImage image)
     : this(image == null ? null : image.PixelMemory)
 {
 }
Ejemplo n.º 12
0
        /// <summary>
        /// This mehtod generates a composite image that includes all layers so we have a full product thumbnail
        /// </summary>
        /// <param name="size"></param>
        /// <param name="d"></param>
        /// <returns></returns>
        public static byte[] Thumbnail(string size, string d)
        {
            Size thumbSize = new Size(107, 67);

            if (size == "medium")
            {
                thumbSize = new Size(160, 100);
            }
            else if (size == "large")
            {
                thumbSize = new Size(320, 200);
            }

            using (AtalaImage image = new AtalaImage(thumbSize.Width, thumbSize.Height, PixelFormat.Pixel32bppBgra, Color.Transparent))
            {
                string product = string.Empty;
                string view    = "default";

                #region Build layers from input json
                //expected format
                //[["productName","Bed"],["Size","Small"],["Top","NavyBlue"],["Side","NavyBlue"],["Piping","Pink"],["text",""],["banner","Oval"],["font","BigDog.TTF"],["textColor","000000"],["image1",""],["image2",""],["image3",""]]
                var      props             = JsonHelper.Decode(d);
                string[] skippedProperties = { "Size", "text", "banner", "font", "textColor", "image1", "image2", "image3" };
                var      layers            = new List <KeyValuePair <string, string> >();
                var      allProperties     = new List <KeyValuePair <string, string> >();
                foreach (var prop in props)
                {
                    string key   = prop[0];
                    string value = prop[1];
                    allProperties.Add(new KeyValuePair <string, string>(key, value));
                    if (skippedProperties.Contains(key))
                    {
                        continue;
                    }
                    if (key == "productName")
                    {
                        product = value;
                    }
                    else
                    {
                        layers.Add(new KeyValuePair <string, string>(key, value));
                    }
                }
                #endregion

                #region Draw Layers
                var g = image.GetGraphics();
                g.TextRenderingHint = TextRenderingHint.AntiAlias;
                #region Draw Base
                string basePath = HttpContext.Current.Server.MapPath(string.Format("~/AppContent/ProductImages/{0}/{1}/base.png", product, view));
                if (File.Exists(basePath))
                {
                    using (AtalaImage uploadImage = new AtalaImage(basePath))
                    {
                        g.DrawImage(uploadImage.ToBitmap(), new RectangleF(0, 0, thumbSize.Width, thumbSize.Height));
                    }
                }
                #endregion
                foreach (var layer in layers)
                {
                    string imgPath = HttpContext.Current.Server.MapPath(string.Format("~/AppContent/ProductImages/{0}/{1}/{2}-{3}.png", product, view, layer.Key, layer.Value));
                    using (AtalaImage uploadImage = new AtalaImage(imgPath))
                    {
                        g.DrawImage(uploadImage.ToBitmap(), new RectangleF(0, 0, thumbSize.Width, thumbSize.Height));
                    }
                }
                #endregion

                #region Draw Text
                //Get product properties
                //string[] skippedProperties = { "Size", "text", "banner", "font", "textColor", "image1", "image2", "image3" };
                var textProp = allProperties.Where(kvp => kvp.Key == "text").FirstOrDefault();
                if (!string.IsNullOrEmpty(textProp.Value))
                {
                    dynamic productSchema = ProductSchemaProvider.GetProductSchema(product);
                    var     defaultView   = productSchema.views[0];
                    var     textLayer     = ((IEnumerable)defaultView.layers).Cast <dynamic>().Where(l => l.displayType == "text").FirstOrDefault();
                    if (textLayer != null)
                    {
                        JToken defaults = (JToken)textLayer.defaults;

                        var colorProp  = allProperties.Where(kvp => kvp.Key == "textColor").FirstOrDefault();
                        var fontProp   = allProperties.Where(kvp => kvp.Key == "font").FirstOrDefault();
                        var bannerProp = allProperties.Where(kvp => kvp.Key == "banner").FirstOrDefault();
                        var image1Prop = allProperties.Where(kvp => kvp.Key == "image1").FirstOrDefault();

                        var placeholderImageLocation = "";

                        // TODO: Clean this up
                        if (image1Prop.Value != null)
                        {
                            if (product == "Frisbee")
                            {
                                placeholderImageLocation = "placeholder";
                            }
                            else
                            {
                                placeholderImageLocation = "placeholder2";
                            }
                        }

                        byte[] textImage = TextImage(defaults.GetValue <string>("drawMode", ""),
                                                     textProp.Value,
                                                     colorProp.Value != null ? colorProp.Value : defaults.GetValue <string>("textColor"),
                                                     defaults.GetValue <int>("Size", 40),
                                                     fontProp.Value != null ? fontProp.Value : defaults.GetValue <string>("font"),
                                                     defaults.GetValue <int>("x", 0),
                                                     defaults.GetValue <int>("y", 0),
                                                     defaults.GetValue <int>("h", 0),
                                                     defaults.GetValue <int>("w", 0),
                                                     defaults.GetValue <int>("r1", 0),
                                                     defaults.GetValue <int>("s2", 0),
                                                     defaults.GetValue <string>("align", ""),
                                                     defaults.GetValue <int>("x2", 320),
                                                     defaults.GetValue <int>("y2", 110),
                                                     defaults.GetValue <int>("h2", 260),
                                                     defaults.GetValue <int>("w2", 220),
                                                     defaults.GetValue <int>("r2", 0),
                                                     defaults.GetValue <int>("s2", 0),
                                                     bannerProp.Value != null ? bannerProp.Value : defaults.GetValue <string>("banner"),
                                                     image1Prop.Value != null ? placeholderImageLocation : string.Empty);
                        using (var textImageMemory = new MemoryStream(textImage))
                        {
                            using (AtalaImage uploadImage = new AtalaImage(textImageMemory))
                            {
                                g.DrawImage(uploadImage.ToBitmap(), new RectangleF(0, 0, thumbSize.Width, thumbSize.Height));
                            }
                        }
                    }
                }
                #endregion

                #region Save Image
                byte[] data = null;
                using (MemoryStream m = new MemoryStream())
                {
                    PngEncoder encoder = new PngEncoder();
                    encoder.Save(m, image, null);
                    data = m.ToArray();
                    return(data);
                }
                #endregion
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// This method generates a single layer of a product image used int the product customization tool
        /// </summary>
        /// <param name="drawMode"></param>
        /// <param name="text"></param>
        /// <param name="textColor"></param>
        /// <param name="size"></param>
        /// <param name="font"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="h"></param>
        /// <param name="w"></param>
        /// <param name="r1"></param>
        /// <param name="s1"></param>
        /// <param name="align"></param>
        /// <param name="x2"></param>
        /// <param name="y2"></param>
        /// <param name="h2"></param>
        /// <param name="w2"></param>
        /// <param name="r2"></param>
        /// <param name="s2"></param>
        /// <param name="banner"></param>
        /// <param name="imgSrc"></param>
        /// <returns></returns>
        public static byte[] TextImage(string drawMode, string text, string textColor, float size, string font, int x, int y, int h, int w, int r1, int s1, string align,
                                       int x2, int y2, int h2, int w2, int r2, int s2, string banner, string imgSrc)
        {
            bool   debug          = false;
            string path           = HttpContext.Current.Server.MapPath(string.Format("~/AppContent/fonts/{0}", font));
            var    fontCollection = new PrivateFontCollection();

            if (TextColorMap.Keys.Contains(textColor))
            {
                textColor = TextColorMap[textColor]; //Replace text colorname from client with the hex value stored in our map
            }
            textColor = "#" + textColor;

            using (var FontFamily = LoadFontFamily(path, out fontCollection))
                using (var DrawFont = new Font(FontFamily, size))
                    using (AtalaImage image = new AtalaImage(856, 500, PixelFormat.Pixel32bppBgra, Color.Transparent))
                    {
                        var g = image.GetGraphics();
                        g.TextRenderingHint = TextRenderingHint.AntiAlias;
                        SizeF textSize   = SizeF.Empty;
                        Font  scaledFont = null;

                        #region Draw Image
                        if (imgSrc != string.Empty)
                        {
                            string imgPath = "";
                            if (imgSrc == "placeholder")
                            {
                                imgPath = HttpContext.Current.Server.MapPath("~/AppContent/RenderImages/uploadPlaceholder.png");
                            }
                            else
                            {
                                imgPath = HttpContext.Current.Server.MapPath("~/AppContent/RenderImages/uploadPlaceholderTwo.png");
                            }
                            //else - handle upladed images
                            using (AtalaImage uploadImage = new AtalaImage(imgPath))
                            {
                                //For rendering image relative to text
                                //float offsetX = 0;
                                //float offsetY = -1 * (h2 / 4);

                                //float padding = 10;
                                //if (align == "center" && textSize.Width == 0)
                                //    offsetX = (w / 2) - (w2 / 2);
                                //else
                                //    offsetX = -1 * (w2 + padding);

                                //g.DrawImage(uploadImage.ToBitmap(), new RectangleF(x + offsetX, y + offsetY, w2, h2));
                                ApplyRotation(g, r2, x2, y2);
                                if (s2 != 0)
                                {//SKEW The image so it looks ok at an angle.  Currently only used on the bed.
                                    Point[] points = new Point[3] {
                                        new Point(x2, y2), new Point(x2 + w2, y2 + s2), new Point(x2, y2 + h2)
                                    };
                                    g.DrawImage(uploadImage.ToBitmap(), points);
                                }
                                else
                                {
                                    g.DrawImage(uploadImage.ToBitmap(), new RectangleF(x2, y2, w2, h2));
                                }
                                FinishRotation(g, r2, x2, y2);
                            }
                        }
                        #endregion
                        if (drawMode != "curved")
                        {
                            #region GetTextSize
                            textSize   = SizeF.Empty;
                            scaledFont = FindGoodFont(g, text, new Size(w, h), DrawFont, GraphicsUnit.Point);

                            textSize = g.MeasureString(text, scaledFont, w, StringFormat.GenericTypographic);
                            #endregion
                            #region DrawBanner
                            if (!string.IsNullOrEmpty(banner) && !string.IsNullOrEmpty(text))
                            {
                                string imgPath = HttpContext.Current.Server.MapPath(string.Format("~/AppContent/RenderImages/banner-{0}.png", banner));
                                using (AtalaImage bannerImage = new AtalaImage(imgPath))
                                {
                                    int bannerWidth  = 211;
                                    int bannerHeight = 86;
                                    //Center banner arround Text placeholder
                                    int bannerOffsetX = (int)((bannerWidth - w) / 2);
                                    int bannerOffsetY = (int)((bannerHeight - h) / 2);
                                    ApplyRotation(g, r1, x, y);
                                    g.DrawImage(bannerImage.ToBitmap(), new Rectangle(new Point(x - bannerOffsetX, y - bannerOffsetY), new Size(bannerWidth, bannerHeight)));
                                    if (debug)
                                    {
                                        g.DrawRectangle(new Pen(new SolidBrush(Color.Green)), new Rectangle(x - bannerOffsetX, y - bannerOffsetY, bannerWidth, bannerHeight));
                                    }
                                    FinishRotation(g, r1, x, y);
                                }
                            }
                            #endregion
                        }
                        #region Draw Text
                        if (debug)
                        {
                            //Debug Outline to assist in template placement
                            ApplyRotation(g, r1, x, y);
                            g.DrawRectangle(new Pen(new SolidBrush(Color.Red)), new Rectangle(x, y, w, h));
                            FinishRotation(g, r1, x, y);
                            ApplyRotation(g, r2, x2, y2);
                            g.DrawRectangle(new Pen(new SolidBrush(Color.Purple)), new Rectangle(x2, y2, w2, h2));
                            FinishRotation(g, r2, x2, y2);
                        }

                        if (drawMode == "curved")
                        {
                            DrawCurvedText(g, text, new Point(x, y), w, (float)((3 * Math.PI) / 4), DrawFont, new SolidBrush(ColorTranslator.FromHtml(textColor)));
                        }
                        else
                        {
                            #region Get String Format
                            StringFormat stringFormat = null;
                            float        offsetY      = 0;
                            if (align.ToLower() == "center")
                            {
                                stringFormat = new StringFormat {
                                    Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center, FormatFlags = StringFormatFlags.NoWrap
                                }
                            }
                            ;
                            else
                            {
                                stringFormat = new StringFormat {
                                    Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near, FormatFlags = StringFormatFlags.NoWrap
                                };
                                offsetY = h2;
                            }
                            #endregion

                            ApplyRotation(g, r1, x, (int)(y + offsetY));
                            g.DrawString(text, scaledFont, new SolidBrush(ColorTranslator.FromHtml(textColor)), new RectangleF(x, y + offsetY, w, h), stringFormat);
                            FinishRotation(g, r1, x, (int)(y + offsetY));

                            //debug
                            ApplyRotation(g, r1, x, (int)(y + offsetY));
                            if (debug)
                            {
                                g.DrawRectangle(new Pen(new SolidBrush(Color.Blue)), new Rectangle(x, (int)(y + offsetY), (int)textSize.Width, (int)textSize.Height));
                                g.DrawRectangle(new Pen(new SolidBrush(Color.HotPink)), new Rectangle(x, (int)(y + offsetY), w, h));
                            }
                            FinishRotation(g, r1, x, (int)(y + offsetY));
                        }
                        #endregion

                        #region Save Image
                        byte[] data = null;
                        using (MemoryStream m = new MemoryStream())
                        {
                            PngEncoder encoder = new PngEncoder();
                            encoder.Save(m, image, null);
                            data = m.ToArray();
                        }
                        fontCollection.Dispose();
                        g.Dispose();
                        return(data);

                        #endregion
                    }
        }