GDI+确实不行....弄了半天只想出了怎样画圆 , 至于那个像闪电的区域, 死活没想出来..等高手...
private void Form1_Paint(object sender, PaintEventArgs e)
{ Rectangle r = new Rectangle(10, 10, 100, 100);
e.Graphics.DrawEllipse(new Pen(Color.Red), r);
e.Graphics.FillEllipse(Brushes.Red, r);
}
等高手.....
private void Form1_Paint(object sender, PaintEventArgs e)
{ Rectangle r = new Rectangle(10, 10, 100, 100);
e.Graphics.DrawEllipse(new Pen(Color.Red), r);
e.Graphics.FillEllipse(Brushes.Red, r);
}
等高手.....
解决方案 »
- winfrom 中 webservice 的调用问题
- WinForm中ListBox.Items.Add()问题
- visual studio 2010 制作应用程序问题
- 自动生成线程的问题
- 当numericUpDown内容用BackSpace键去除变为空白时,引发CausesValidation,让程序停顿数秒无反应??
- reportview 报表中 2个字符串相连接 如何相连 ?
- 新手求教
- 100分求vs.net 2003,msdn 2003,4月的
- 谢谢各位高手,再问一个问题,怎么让弹出的窗口在屏幕中间,并且弹到最上面,还有各位告诉我的方法,弹出窗口以后,在托盘中又出现了一个
- winform界面,为啥不可见?
- 急阿!如何调用WebService
- 程序很不稳定,有时出现以下错误,有时又不出现,奇怪
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias可以消除锯齿, 明显好多了....
{
Graphics g = e.Graphics;
PointF pO = new PointF(60, 50);//园左上焦点
int c = 300;//园直径
int plWidth = c / 3;
float plWidthHalf = plWidth / 2.0f;
GraphicsPath p = new GraphicsPath();//闪电路径
GraphicsPath pH = new GraphicsPath();//闪电路径
//设白闪电为头部朝下的霹雳
PointF py = new PointF(pO.X + c / 2.0f, pO.Y); PointF pgL0 = new PointF(py.X - plWidthHalf, pO.Y + 10);
PointF pgR0 = new PointF(py.X + plWidthHalf, pO.Y + 10); PointF pgL1 = new PointF(py.X - plWidthHalf * 0.8f - 6, pO.Y + c * 0.2f);
PointF pgR1 = new PointF(py.X + plWidthHalf * 0.8f - 6, pO.Y + c * 0.2f); PointF pgL2 = new PointF(py.X - plWidthHalf * 0.6f + 5, pO.Y + c * 0.4f);
PointF pgR2 = new PointF(py.X + plWidthHalf * 0.6f + 5, pO.Y + c * 0.4f); PointF pgL3 = new PointF(py.X - plWidthHalf * 0.4f - 4, pO.Y + c * 0.6f);
PointF pgR3 = new PointF(py.X + plWidthHalf * 0.4f - 4, pO.Y + c * 0.6f); PointF pgL4 = new PointF(py.X - plWidthHalf * 0.2f + 3, pO.Y + c * 0.8f);
PointF pgR4 = new PointF(py.X + plWidthHalf * 0.2f + 3, pO.Y + c * 0.8f);
PointF gt = new PointF(pO.X + c / 2.0f, pO.Y + c); p.AddLine(pgL0, pgL1);
p.AddLine(pgL1, pgL2);
p.AddLine(pgL2, pgL3);
p.AddLine(pgL3, pgL4);
p.AddLine(pgL4, gt);
p.AddLine(gt, pgR4);
p.AddLine(pgR4, pgR3);
p.AddLine(pgR3, pgR2);
p.AddLine(pgR2, pgR1);
p.AddLine(pgR1, pgR0);
pH.AddPie(pO.X, pO.Y, c, c, -110, 40); g.FillEllipse(Brushes.Red, pO.X, pO.Y, c, c);
g.FillPath(Brushes.White, p);
g.FillPath(Brushes.White, pH); }
将膏药旗撕开为两片,不是将膏药旗啃掉一块(绘制、填充一个圆,去掉中间一块)。[/size]
2。画中间的波浪线
3。套索勾选左半边,然后自由形变,旋转一个角度
4。勾选右半边半边,然后自由形变,旋转一个角度呵呵,明白过程了,用gdi+模拟这个过程就成
期待 i n g 。 。 。
//放到Form的Paint事件中Graphics g=e.Graphics;
g.SmoothingMode=SmoothingMode.HighQuality;
g.TranslateTransform(300,300);
g.RotateTransform(5f);
Point[] ps=new Point[]{
new Point(0,-100)
,new Point(-3,-92)
,new Point(2,-85)
,new Point(-5,-76)
,new Point(3,-65)
,new Point(-2,-57)
,new Point(4,-49)
,new Point(-3,-30)
,new Point(1,-13)
,new Point(-2,-9)
,new Point(0,0)
};Point[] ps1=ps.ToArray<Point>();
Rectangle rect=new Rectangle(-50,-100,100,100);
GraphicsPath myPath=new GraphicsPath();myPath.StartFigure();
Array.Reverse(ps);
myPath.AddLines(ps);
myPath.AddArc(rect,270,180);
myPath.CloseFigure();
g.DrawPath(new Pen(Color.Red,1),myPath);
g.FillPath(new SoldBrush(Color.Red),myPath);myPath=new GraphicsPath();myPath.StartFigure();
myPath.AddLines(ps1);
myPath.AddArc(rect,90,180);
myPath.CloseFigure();
g.DrawPath(new Pen(Color.Red,1),myPath);
g.FillPath(new SoldBrush(Color.Red),myPath);
撕开的形状和楼主的不太一样,这个需要慢慢的调
在myPath=new GraphicsPath();
上面增加一句 g.RotateTransform( -10f );
完整代码如下: private void Form1_Paint( object sender, PaintEventArgs e )
{
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.HighQuality;
g.TranslateTransform( 300, 300 );
g.RotateTransform( 5f );
Point[] ps = new Point[]{
new Point(0,-100)
,new Point(-3,-92)
,new Point(2,-85)
,new Point(-5,-76)
,new Point(3,-65)
,new Point(-2,-57)
,new Point(4,-49)
,new Point(-3,-30)
,new Point(1,-13)
,new Point(-2,-9)
,new Point(0,0)
}; Point[] ps1 = ps.ToArray<Point>();
Rectangle rect = new Rectangle( -50, -100, 100, 100 );
GraphicsPath myPath = new GraphicsPath(); myPath.StartFigure();
Array.Reverse( ps );
myPath.AddLines( ps );
myPath.AddArc( rect, 270, 180 );
myPath.CloseFigure();
g.DrawPath( new Pen( Color.Red, 1 ), myPath );
g.FillPath( new SolidBrush( Color.Yellow ), myPath );
g.RotateTransform( -10f );
myPath = new GraphicsPath(); myPath.StartFigure();
myPath.AddLines( ps1 );
myPath.AddArc( rect, 90, 180 );
myPath.CloseFigure();
g.DrawPath( new Pen( Color.Red, 1 ), myPath );
g.FillPath( new SolidBrush( Color.Green ), myPath );
}
测试环境:
WinXP(SP2)、VS2008(SP1)、Framework3.5(SP1)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing.Imaging;
public class Form1
{
Bitmap BP_0;
/// <summary>
/// 太阳半径
/// </summary>
/// <res></res>
private int SunRadio = 150;
/// <summary>
/// 裂口段数
/// </summary>
/// <res></res>
private int LightStb = 8; private void Form1_Load(System.Object sender, System.EventArgs e)
{
} private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
PointF[] Pts = new PointF[LightStb + 2];
using (Bitmap B1 = new Bitmap(SunRadio, SunRadio)) {
using (Graphics G = Graphics.FromImage(B1)) {
G.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias;
Pts(0) = new Point(SunRadio / 2, 0);
Pts(9) = new Point(SunRadio / 2, SunRadio);
for (int I = 1; I <= LightStb; I++) {
if (I % 2 != 0) {
Pts(I) = new Point(SunRadio / 2 - 50 / I / 2, SunRadio / 8 * I);
} else {
Pts(I) = new Point(SunRadio / 2 + 50 / I / 2, SunRadio / 8 * I);
}
}
using (Drawing2D.GraphicsPath Gp = new Drawing2D.GraphicsPath()) {
Gp.AddLines(Pts);
Gp.AddArc(new Rectangle(0, 0, SunRadio, SunRadio), 90, 180);
G.FillPath(Brushes.Red, Gp);
}
}
using (Bitmap B2 = new Bitmap(SunRadio, SunRadio)) {
using (Drawing2D.GraphicsPath Gp = new Drawing2D.GraphicsPath()) {
Gp.AddLines(Pts);
Gp.AddArc(new Rectangle(0, 0, SunRadio, SunRadio), -90, 180);
using (Graphics G = Graphics.FromImage(B2)) {
G.FillPath(Brushes.Red, Gp);
}
}
using (Bitmap B3 = new Bitmap(SunRadio, SunRadio)) {
using (Bitmap B4 = new Bitmap(SunRadio, SunRadio)) {
using (Graphics G = Graphics.FromImage(B3)) {
G.TranslateTransform(SunRadio / 2, SunRadio / 2);
G.RotateTransform(-5);
G.DrawImage(B1, new Rectangle(-SunRadio / 2, -SunRadio / 2, SunRadio, SunRadio), new Rectangle(0, 0, SunRadio, SunRadio), GraphicsUnit.Pixel);
}
using (Graphics G = Graphics.FromImage(B4)) {
G.TranslateTransform(SunRadio / 2, SunRadio / 2);
G.RotateTransform(5);
G.DrawImage(B2, new Rectangle(-SunRadio / 2, -SunRadio / 2, SunRadio, SunRadio), new Rectangle(0, 0, SunRadio, SunRadio), GraphicsUnit.Pixel);
}
if (BP_0 != null)
BP_0.Dispose();
BP_0 = new Bitmap(SunRadio + 30, SunRadio);
using (Graphics G = Graphics.FromImage(BP_0)) {
G.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias;
G.DrawImage(B3, new Point(0, 0));
G.DrawImage(B4, new Point(15, 0));
this.BackgroundImageLayout = ImageLayout.Center;
this.BackgroundImage = BP_0;
}
}
}
}
}
}
public Form1()
{
MouseDown += Form1_MouseDown;
Load += Form1_Load;
}
}
{
Graphics g = this.CreateGraphics();
g.SmoothingMode = SmoothingMode.AntiAlias;
g.FillEllipse(Brushes.Red, new Rectangle(80, 70, 120, 120));
GraphicsPath gpth = new GraphicsPath();
Point[] pt = new Point[]
{new Point(130, 70), new Point(130, 110), new Point(130, 130), new Point(140, 150), new Point(135, 160), new Point(140, 170) ,new Point(135, 188),
new Point(140, 188), new Point(143, 190), new Point(144, 188), new Point(140, 180), new Point(145, 170), new Point(140, 160), new Point(144, 150),
new Point(137, 129), new Point(145, 120), new Point(142, 108), new Point(150, 70)};
gpth.AddLines(pt);
g.FillPath(Brushes.White, gpth);
}