示例#1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            Template.Name = txtName.Text.Trim();
            Template.Text = txtText.Text.Trim();

            OutlineTextProcessor outlineTextProcessor = new OutlineTextProcessor(fakeModelItem, Template, fontPath);
            resultImage = outlineTextProcessor.GetImage();

            using (MemoryStream memoryStream = new MemoryStream())
            {
                resultImage.Save(memoryStream, ImageFormat.Png);
                Template.Image = memoryStream.ToArray();
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
        //ToDo -
        private void ModelToSampleForm_Load(object sender, EventArgs e)
        {
            string fontPath = @"E:\xWork\Apps\Work\AddTextToImage\AddTextToImage.WebUI\fonts\";

            model = _modelRepository.Get(ModelId);

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

                Graphics graphics = Graphics.FromImage(bmpResult);

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

                    if (modelItem.ItemType == 0)
                    {
                        template = _textTemplateRepository.GetAllWithInclude("Font").Where(p => p.Id == modelItem.TemplateId).FirstOrDefault();
                    }
                    else
                    {
                        template = _clipartTemplateRepository.GetAllWithInclude("Font").Where(p => p.Id == modelItem.TemplateId).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();
            }
        }
示例#3
0
        private void UpdateImage()
        {
            if (!String.IsNullOrWhiteSpace(fakeModelItem.Text))
            {
                fakeModelItem.FontColor = ColorTranslator.ToHtml(Color.FromArgb(Template.TextColor1));

                OutlineTextProcessor outlineTextProcessor = new OutlineTextProcessor(fakeModelItem, Template, fontPath);
                resultImage = outlineTextProcessor.GetImage();
            }
            else
                resultImage = new Bitmap(1, 1);

            lbldWidth.Text = resultImage.Width.ToString();
            lbldHeight.Text = resultImage.Height.ToString();

            panel1.Refresh();
        }
示例#4
0
        public static Bitmap GetResultImage(Model model)
        {
            string fontPath = @"E:\xWork\Apps\Work\AddTextToImage\AddTextToImage.WebUI\fonts\";

            IRepository<TextTemplate> _textTemplateRepository = new Repository<TextTemplate>(new DbContextFactory());
            IRepository<ClipartTemplate> _clipartTemplateRepository = new Repository<ClipartTemplate>(new DbContextFactory());

            if (model == null)
                return null; //ToDo

            ImageConverter ic = new ImageConverter();
            Image img = (Image)ic.ConvertFrom(model.Image);
            Bitmap bmpResult = new Bitmap(img);

            Graphics graphics = Graphics.FromImage(bmpResult);

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

                if (modelItem.ItemType == 0)
                {
                    template = _textTemplateRepository.GetAllWithInclude("Font").Where(p => p.Id == modelItem.TemplateId).FirstOrDefault();
                }
                else
                {
                    template = _clipartTemplateRepository.GetAllWithInclude("Font").Where(p => p.Id == modelItem.TemplateId).FirstOrDefault();
                }

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

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

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

            return bmpResult;
        }
        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();
        }