private void tsbtnCopyModelToSample_Click(object sender, EventArgs e)
        {
            CurrencyManager cm = (CurrencyManager)this.BindingContext[dgvModels.DataSource, dgvModels.DataMember];

            Model model = (Model)cm.Current;

            Sample sample = new Sample();
            sample.Items = new List<SampleItem>();

            sample.ContentType = model.ContentType;
            sample.Image = model.Image;
            sample.ImageWidth = model.ImageWidth;
            sample.ImageHeight = model.ImageHeight;

            Bitmap bmpThumbnail = Utilities.Utils.ResizeImage(Utils.ByteArrayToBitmap(model.Image), 360, 270);
            sample.Thumbnail = Utilities.Utils.BitmapToByteArray(bmpThumbnail);

            foreach (ModelItem modelItem in model.Items)
            {
                SampleItem sampleItem = new SampleItem();

                sampleItem.ItemType = modelItem.ItemType;
                sampleItem.PositionTop = modelItem.PositionTop;
                sampleItem.PositionLeft = modelItem.PositionLeft;
                sampleItem.Text = modelItem.Text;
                sampleItem.TemplateId = modelItem.TemplateId;
                sampleItem.FontSize = modelItem.FontSize;
                sampleItem.FontColor = modelItem.FontColor;
                sampleItem.Rotation = modelItem.Rotation;

                sample.Items.Add(sampleItem);
            }

            _sampleRepository.Add(sample);
            _sampleRepository.Save();
        }
        private void tsbtnToSample_Click(object sender, EventArgs e)
        {
            string fontPath = @"E:\xWork\Apps\Work\AddTextToImage\AddTextToImage.WebUI\fonts\";
            Bitmap bmpResult;

            if (model != null)
            {
                ImageConverter ic = new ImageConverter();
                Image img = (Image)ic.ConvertFrom(model.Image);
                bmpResult = new Bitmap(img);

                Graphics graphics = Graphics.FromImage(bmpResult);

                foreach (var modelItem in model.Items)
                {
                    TemplateBase template = null;

                    if (modelItem.ItemType == 0)
                    {
                        template =
                            (from t in _textTemplateRepository.GetAllWithInclude("Font")
                             where t.Id == modelItem.TemplateId
                             select t).FirstOrDefault();
                    }
                    else
                    {
                        template =
                            (from t in _clipartTemplateRepository.GetAllWithInclude("Font")
                             where t.Id == modelItem.TemplateId
                             select t).FirstOrDefault();

                    }

                    OutlineTextProcessor outlineTextProcessor = new OutlineTextProcessor(modelItem, template, fontPath);
                    Bitmap image = outlineTextProcessor.GetImage();

                    graphics.DrawImage((Image)image, new Point(modelItem.PositionLeft, modelItem.PositionTop));
                }

                resultImage = bmpResult;

                graphics.Flush();
                graphics.Dispose();
            }

            Sample sample = new Sample();
            sample.Items = new List<SampleItem>();

            sample.ContentType = model.ContentType;
            sample.Image = model.Image;
            sample.ImageWidth = model.ImageWidth;
            sample.ImageHeight = model.ImageHeight;

            Bitmap bmpThumbnail = Utilities.Utils.ResizeImage(resultImage, 360, 270);
            sample.Thumbnail = Utilities.Utils.BitmapToByteArray(bmpThumbnail);

            foreach (ModelItem modelItem in model.Items)
            {
                SampleItem sampleItem = new SampleItem();

                sampleItem.ItemType = modelItem.ItemType;
                sampleItem.PositionTop = modelItem.PositionTop;
                sampleItem.PositionLeft = modelItem.PositionLeft;
                sampleItem.Text = modelItem.Text;
                sampleItem.TemplateId = modelItem.TemplateId;
                sampleItem.FontSize = modelItem.FontSize;
                sampleItem.FontColor = modelItem.FontColor;
                sampleItem.Rotation = modelItem.Rotation;

                sample.Items.Add(sampleItem);
            }

            _sampleRepository.Add(sample);
            _sampleRepository.Save();
        }