最近实现了C#绘制手提袋效果和光盘效果:
(1)
代码:
BagPackageEffect bpe = new BagPackageEffect();
bpe.IsUseSamePhoto = false;
bpe.UserPhotoFileName = @"D:/20070520011714942.jpg";
bpe.ImageLeftSideFileName = @"D:/20070419171728790.jpg";
bpe.BgColor = Color.Transparent;
bpe.FrontFaceBgColor = Color.DarkOrange;
bpe.LeftSideBgColor = Color.Bisque;
m_Bitmap = (Bitmap)bpe.Draw();
bpe.Dispose();
(2)光盘效果:
Disk disk = new Disk();
disk.IsUseBgImage = false;
disk.BgColor = Color.Black;
disk.ImageBgFileName = @"D:/20070520023536133.jpg";
disk.BorderColor = Color.Black;
disk.BorderWidth = 1;
disk.BorderInnerPen = new Pen(Color.Red, 1);
disk.DiskBorderBrush = new LinearGradientBrush(new Rectangle(0, 0, 1000, 1000), Color.White, Color.Gray, 45f, true);
disk.IsUseContentImage = true;
disk.ImageContentFileName = @"D:/20070520023536133.jpg";
disk.DiskCenterBrush = new LinearGradientBrush(new Rectangle(0,0,500,500), Color.Red, Color.Orange, 135f);
m_Bitmap = (Bitmap)disk.Draw();
disk.Dispose();
(3)带背景图片的光盘效果(注意光盘中空部分,对背景而言,它是透明的):
绘制部分的关键代码:
g.SmoothingMode = SmoothingMode.AntiAlias;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
if(this._isUseBgImage)
{
GraphicsPath gp = new GraphicsPath();
gp.AddRectangle(new Rectangle(0, 0, 1000, 1000));
g.DrawImage(FillPhotoInZone((Bitmap)this.ImageBg, gp), 0, 0);
gp.Dispose();
}
else
{
g.Clear(this._bgColor);
}
//光盘边缘区
GraphicsPath gpBorder = new GraphicsPath();
gpBorder.AddEllipse(this.diskBorder_Outer);
gpBorder.AddEllipse(this.diskBorder_Inner);
gpBorder.FillMode = FillMode.Alternate;
g.SetClip(gpBorder);
g.FillEllipse(this._diskBorderBrush, this.diskBorder_Outer);
gpBorder.Dispose();
g.ResetClip();
//光盘内容区
GraphicsPath gpContent = new GraphicsPath();
gpContent.AddEllipse(this.diskBorder_Inner);
gpContent.AddEllipse(this.diskCenter);
gpContent.FillMode = FillMode.Alternate;
g.SetClip(gpContent);
if(this.IsUseContentImage)
{
g.DrawImage(this.ImageContent, this.diskBorder_Inner, new Rectangle(0, 0, this.ImageContent.Width, this.ImageContent.Height), GraphicsUnit.Pixel);
}
else
{
g.FillEllipse(this._diskContentBrush, this.diskBorder_Inner);
}
gpContent.Dispose();
g.ResetClip();
//光盘托面区
GraphicsPath gpBearingSurface = new GraphicsPath();
gpBearingSurface.AddEllipse(this.diskCenter);
gpBearingSurface.AddEllipse(this.diskInner);
gpBearingSurface.FillMode = FillMode.Alternate ;
g.SetClip(gpBearingSurface);
_diskCenterBrush = new SolidBrush(Color.FromArgb(160, 255, 255, 255));
g.FillEllipse(this._diskCenterBrush, this.diskCenter);
gpBearingSurface.Dispose();
g.ResetClip ();
g.DrawEllipse(this._borderPen, this.diskBorder_Outer);
g.DrawEllipse(this._borderInnerPen, this.diskBorder_Inner);
g.DrawEllipse(this._borderDiskCenterPen, this.diskCenter);
g.DrawEllipse(this._borderDiskInnerPen, this.diskInner);
//g.DrawLine(new Pen(Color.Red, 1), new Point(500,0), new Point(500, 1000));
//g.DrawLine(new Pen(Color.Red, 1), new Point(0,500), new Point(1000, 500));
//gpDiskInner.Dispose();
gpBorder.Dispose ();
更多效果将陆续放在http://www.zpxp.com(萝卜鼠在线图形图像处理)中.
已实现了WPF下的手提袋效果:(右边为代码截图)