利用C#制作公章

先看一下效果图:


代码:
private void button1_Click(object sender, System.EventArgs e)
  {
   Graphics g = this.CreateGraphics();
   g.Clear(Color.White);
   //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
   g.CompositingQuality = CompositingQuality.HighQuality;
   g.SmoothingMode = SmoothingMode.HighQuality;
           
   int radius = 200;
   CircularTextualLayout ctl = new CircularTextualLayout();
   ctl.Radius = radius;
   Point location = new Point(50, 20);
   //ctl.CenterPoint = new Point(location.X + radius, location.Y + radius);
   ctl.TextDrawing = "方正姚体方正姚体方正姚体方正姚体";

   float arcAngle = 270;
   ctl.ArcAngle = arcAngle;
   ctl.AngleStart = -arcAngle/2 + arcAngle/2/ctl.TextDrawing.Length;
   ctl.TextFontInner = new Font("方正姚体", radius/3.2f);
   ctl.RatioX = 0.6f;
   ctl.BorderWidth = (int)(ctl.Radius / 40);
   //ctl.IsBold = false;
   ctl.Location = location;
   ctl.WordsColor = Color.FromArgb(250, Color.Red);
   ctl.BorderColor = Color.FromArgb(250, Color.Red);
   ctl.RectColor = Color.FromArgb(250, Color.Red);
   ctl.Draw(g);

   g.Dispose();
  }

公章样式的水印图片(截图):

 


 
private void button2_Click(object sender, System.EventArgs e)
  {
   Graphics g = this.CreateGraphics();
   g.Clear(Color.White);
   //g.DrawImage(Image.FromFile(@"F:\imgs\girl\227.jpg"), 0, 0);
   g.DrawImage(Image.FromFile(@"D:\JohnsunTest\aa\05290_b11.jpg"), 0, 0);
   //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
   g.CompositingQuality = CompositingQuality.HighQuality;
   g.SmoothingMode = SmoothingMode.HighQuality;
           
   int radius = 100;
   int offset = 1;
   CircularTextualLayout ctl = new CircularTextualLayout();
   ctl.Radius = radius;
   Point location = new Point(500, 100);
   //ctl.CenterPoint = new Point(location.X + radius, location.Y + radius);
   ctl.TextDrawing = "公章样式之水印图片制作";

   float arcAngle = 270;
   //ctl.AngleStart = -105+ 210/ctl.TextDrawing.Length/2;
   ctl.ArcAngle = arcAngle;
   //ctl.AngleStart = (arcAngle/2) * ( - 1 + 1/ctl.TextDrawing.Length);
   ctl.AngleStart = -arcAngle/2 + arcAngle/2/ctl.TextDrawing.Length;
   //ctl.TextFontInner = new Font("方正小篆体", 56f);
   ctl.TextFontInner = new Font("方正姚体", radius/3.2f);
   ctl.RatioX = 0.6f;
   ctl.BorderWidth = (int)(ctl.Radius / 40);
   //ctl.IsBold = false;
   ctl.Location = location;
   ctl.WordsColor = Color.FromArgb(160, Color.Black);
   ctl.BorderColor = Color.FromArgb(160, Color.Black);
   ctl.RectColor = Color.FromArgb(160, Color.Black);
   ctl.Draw(g);

   location.Offset(-offset*2, -offset*2);
   ctl.Location = location;
   ctl.WordsColor = Color.FromArgb(160, Color.White);
   ctl.BorderColor = Color.FromArgb(60, Color.White);
   ctl.RectColor = Color.FromArgb(160, Color.White);
   ctl.Draw(g);

   g.Dispose();
  }

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/johnsuna/archive/2006/03/13/622836.aspx
(后续:)

运行效果图:


关键C#代码:
// OfficialSeal.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using brawdrawSharp = BrawDraw.Com.Utility.PublicClasses.Shape;

namespace BrawDraw.Com.WPF.PublicControls.Demo
{
    public class OfficialSeal : Window
    {
        [STAThread]
        public static void Main()
        {
            Application app = new Application();
            app.Run(new OfficialSeal());
        }

        public OfficialSeal()
        {
            string officialSealText = "BRAWDRAW图文印章示例";
            Title = officialSealText;

            Canvas canv = new Canvas();
            Content = canv;
            Ellipse ellipse = new Ellipse();
            ellipse.Width = 400;
            ellipse.Height = 400;
            ellipse.Stroke = new SolidColorBrush(Colors.Red);
            ellipse.StrokeThickness = 2;
            Canvas.SetLeft(ellipse, 10);
            canv.Children.Add(ellipse);

            double angleAdd = 236.00 / officialSealText.Length;
            int i = 0;
            for (double angle = -112; angle < 123; angle += angleAdd)
            {
                TextBlock txtblk = new TextBlock();
                txtblk.FontFamily = new FontFamily("方正大标宋简体,黑体,宋体");
                txtblk.FontSize = 56;
                txtblk.Foreground = new SolidColorBrush(Colors.Red);
                txtblk.Text = officialSealText[i].ToString();
                txtblk.RenderTransformOrigin = new Point(0.5, 0);
                TransformGroup tg = new TransformGroup();
                ScaleTransform st = new ScaleTransform(0.66, 1);
                TranslateTransform tt = new TranslateTransform(0, -188);
                tg.Children.Add(st);
                tg.Children.Add(tt);
                tg.Children.Add(new RotateTransform(angle));
                txtblk.RenderTransform = tg;
                canv.Children.Add(txtblk);
                Canvas.SetLeft(txtblk, 180);
                Canvas.SetTop(txtblk, 200);
                i++;
            }

            Path myPath = new Path();
            myPath.Stroke = Brushes.Red;
            myPath.StrokeThickness = 1;

// 正五角星
            StreamGeometry theGeometry = BuildPentagonalStars(new Point(180, 168), 80, 80);
            theGeometry.FillRule = FillRule.EvenOdd;
            theGeometry.Freeze();
            myPath.Data = theGeometry;
            myPath.Fill = Brushes.Red;
            canv.Children.Add(myPath);
        }

        StreamGeometry BuildPentagonalStars(Point location, int width, int height)
        {
            Point[] pointsPentagonalStars = brawdrawSharp.RegularPolygon.GetStarPoints(location, width, height);
            StreamGeometry geometry = new StreamGeometry();

            using (StreamGeometryContext ctx = geometry.Open())
            {
                ctx.BeginFigure(new Point(pointsPentagonalStars[0].X, pointsPentagonalStars[0].Y), true, true);
                for (int i = 0; i < pointsPentagonalStars.Length; i++)
                {
                    ctx.LineTo(pointsPentagonalStars[i], true, false);
                }
            }

            return geometry;
        }

    }
}

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/johnsuna/archive/2008/04/28/2336495.aspx

 

posted @ 2009-08-19 14:39  oraclejava  阅读(1599)  评论(0)    收藏  举报