//public float GradientWidth = 0f; //public Color GradientColor1 = Color.DarkGray; //public Color GradientColor2 = Color.DarkGray; //public Color GradientColor3 = Color.DarkGray; //public float GradientOpaque = 100f; //public float ShadowWidth = 0f; //public Color ShadowColor = Color.DarkGray; //public float ShadowOpaque = 100f; //public float GlowWidth = 0f; //public Color GlowColor = Color.WhiteSmoke; //public float GlowOpaque = 100f; //public float OutlineWidth = 0f; //public Color OutlineColor = Color.WhiteSmoke; //public float OutlineOpaque = 100f; #endregion public PinOption Clone() { var result = new PinOption(); result.Enabled = this.Enabled; result.Mode = this.Mode; result.Tile = this.Tile; result.Blend = this.Blend; result.Opacity = this.Opacity; result.Location = this.Location; result.Offset = this.Offset; result.Pos = this.Pos; result.RandomPos = this.RandomPos; result.FilterParams = this.FilterParams; result.Text = this.Text; result.TextColor = this.TextColor; result.TextFace = this.TextFace; result.TextFont = this.TextFont; result.TextFontStyle = this.TextFontStyle; result.TextSize = this.TextSize; result.PictureFile = this.PictureFile; result.TagFile = this.TagFile; return(result); }
protected internal Bitmap DrawText(Bitmap dst, PinOption option, bool objectOnly = false) { Bitmap result = new Bitmap(dst); if (!string.IsNullOrEmpty(option.Text)) { var align = string.Empty; //if ( option.Pos == CornerRegionType.TopLeft || option.Pos == CornerRegionType.MiddleLeft || option.Pos == CornerRegionType.BottomLeft ) // align = "Left"; //else if ( option.Pos == CornerRegionType.TopCenter || option.Pos == CornerRegionType.MiddleCenter || option.Pos == CornerRegionType.BottomCenter ) // align = "Center"; //else if ( option.Pos == CornerRegionType.TopRight || option.Pos == CornerRegionType.MiddleRight || option.Pos == CornerRegionType.BottomRight ) // align = "Right"; option.ImageCache = option.Text.ToBitmap(option.TextFont, (option.TextFace + $" {align}").Trim(), option.TextSize, option.TextColor.ToColor()); result = DrawPicture(dst, option, objectOnly); } return(result); }
/// <summary> /// /// </summary> /// <param name="image"></param> /// <returns></returns> public override Image Apply(Image image) { GetParams(fm); if (!(image is Image)) { return(image); } var st = DateTime.Now.Ticks; Bitmap dst = AddinUtils.CloneImage(image) as Bitmap; PinObjectMode PinObjectMode = (PinObjectMode)Params["PinObjectMode"].Value; bool objectOnly = (bool)Params["PinObjectOnly"].Value; PinOption option = (PinOption)Params["PinOption"].Value; switch (PinObjectMode) { case PinObjectMode.Picture: dst = DrawPicture(dst, option, objectOnly); break; case PinObjectMode.Text: dst = DrawText(dst, option, objectOnly); break; case PinObjectMode.Tag: break; } AddinUtils.CloneExif(image, dst); float tc = new TimeSpan(DateTime.Now.Ticks - st).Seconds + new TimeSpan(DateTime.Now.Ticks - st).Milliseconds / 1000f; Host.OnCommandPropertiesChange(new CommandPropertiesChangeEventArgs(AddinCommand.ApplyTiming, tc)); return(dst); }
private void btnOpenFont_Click(object sender, EventArgs e) { var optionBackup = option.Clone(); dlgFontEx.UseFont = false; dlgFontEx.FamilyName = option.TextFont; dlgFontEx.TypefaceName = option.TextFace; dlgFontEx.Size = option.TextSize; dlgFontEx.Color = option.TextColor.ToColor(); if (dlgFontEx.ShowDialog() == DialogResult.OK) { option.TextFont = dlgFontEx.FamilyName; option.TextFace = dlgFontEx.TypefaceName; option.TextSize = dlgFontEx.Size; option.TextColor = dlgFontEx.Color.ToHtml(); Preview(); } else { option = optionBackup; Preview(); } }
protected internal Bitmap DrawPicture(Bitmap dst, PinOption option, bool objectOnly = false) { Bitmap result = new Bitmap(dst); if (option.ImageCache is Image) { Bitmap src = new Bitmap(option.ImageCache); #region Calc Margin & Offset PointF margin = new PointF(option.Margin.X / 100f * dst.Width, option.Margin.Y / 100f * dst.Height); PointF offset = new PointF(option.Offset.X / 100f * src.Width, option.Offset.Y / 100f * src.Height); #endregion #region Calc Location PointF pos = new PointF(0, 0); if (option.RandomPos) { Random rnd = new Random(); pos.X = (float)rnd.NextDouble() * (dst.Width - src.Width); pos.Y = (float)rnd.NextDouble() * (dst.Height - src.Height); } else { #region Calc Corner / Side Position switch (option.Pos) { case CornerRegionType.TopLeft: pos.X = margin.X; pos.Y = margin.Y; break; case CornerRegionType.TopCenter: pos.X = margin.X + (dst.Width - src.Width) / 2f; pos.Y = margin.Y; break; case CornerRegionType.TopRight: pos.X = -margin.X + (dst.Width - src.Width); pos.Y = margin.Y; break; case CornerRegionType.MiddleLeft: pos.X = margin.X; pos.Y = margin.Y + (dst.Height - src.Height) / 2f; break; case CornerRegionType.MiddleCenter: pos.X = margin.X + (dst.Width - src.Width) / 2f; pos.Y = margin.Y + (dst.Height - src.Height) / 2f; break; case CornerRegionType.MiddleRight: pos.X = -margin.X + (dst.Width - src.Width); pos.Y = margin.Y + (dst.Height - src.Height) / 2f; break; case CornerRegionType.BottomLeft: pos.X = margin.X; pos.Y = -margin.Y + (dst.Height - src.Height); break; case CornerRegionType.BottomCenter: pos.X = margin.X + (dst.Width - src.Width) / 2f; pos.Y = -margin.Y + (dst.Height - src.Height); break; case CornerRegionType.BottomRight: pos.X = -margin.X + (dst.Width - src.Width); pos.Y = -margin.Y + (dst.Height - src.Height); break; default: pos.X = option.Location.X + margin.X; pos.Y = option.Location.Y + margin.Y; break; } //pos.X = pos.X >= 0 ? pos.X : 0; //pos.Y = pos.Y >= 0 ? pos.Y : 0; //pos.X = pos.X > dst.Width - option.ImageCache.Width ? dst.Width - option.ImageCache.Width : pos.X; //pos.Y = pos.Y > dst.Height - option.ImageCache.Height ? dst.Height - option.ImageCache.Height : pos.Y; #endregion } #endregion #region Make Tile Image if (option.Tile) { RectangleF rect = new RectangleF(0, 0, src.Width, src.Height); rect.Inflate(margin.X / 2f, margin.Y / 2f); //rect = RectangleF.Inflate(rect, margin.X / 2f, margin.Y / 2f ); Bitmap tileElement = new Bitmap((int)Math.Round(rect.Width * 2), (int)Math.Round(rect.Height) * 2, PixelFormat.Format32bppArgb); using (var g = Graphics.FromImage(tileElement)) { PointF p00 = new PointF(margin.X / 2f, margin.Y / 2f); PointF p01 = new PointF(p00.X + rect.Width, p00.Y); PointF p10 = new PointF(offset.X - rect.Width, p00.Y + rect.Height); PointF p11 = new PointF(p10.X + rect.Width, p10.Y); PointF p12 = new PointF(p11.X + rect.Width, p10.Y); g.DrawImage(src, p00); g.DrawImage(src, p01); g.DrawImage(src, p10); g.DrawImage(src, p11); g.DrawImage(src, p12); } int nw = (int)Math.Ceiling(Math.Sqrt(Math.Pow(dst.Width, 2) + Math.Pow(dst.Height, 2))); Bitmap tile = new Bitmap(nw, nw, PixelFormat.Format32bppArgb); using (var g = Graphics.FromImage(tile)) { Brush tb = new TextureBrush(tileElement); g.FillRectangle(tb, 0, 0, nw, nw); } src = tile; } #endregion #region Apply Filters foreach (IAddin filter in Filters) { if (filter.Enabled) { if (option.FilterParams.ContainsKey(filter)) { filter.Params = option.FilterParams[filter]; } src = filter.Apply(src as Image) as Bitmap; } } #endregion if (objectOnly) { return(src); } #region Draw Picture to Image using (Graphics g = Graphics.FromImage(result)) { g.CompositingMode = CompositingMode.SourceOver; g.CompositingQuality = CompositingQuality.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.SmoothingMode = SmoothingMode.AntiAlias; g.TextContrast = 2; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; ColorMatrix c = new ColorMatrix() { Matrix33 = option.Opacity / 100f }; ImageAttributes a = new ImageAttributes(); a.SetColorMatrix(c, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); //Matrix m = new Matrix(); //m.RotateAt( ARotate + factorR, TGPPointF.Create( s.X / 2, s.Y / 2 ) ); //g.MultiplyTransform( m ); if (option.Tile) { pos.X = (dst.Width - src.Width) / 2f; pos.Y = (dst.Height - src.Height) / 2f; } g.DrawImage(src, new Rectangle((int)Math.Round(pos.X), (int)Math.Round(pos.Y), src.Width, src.Height), 0, 0, src.Width, src.Height, GraphicsUnit.Pixel, a); } #endregion #if DEBUG #endif return(result); } return(result); }