就是去行的时候,只看到一个小球在桌面上就可以了,我用以下代码只能实现小球在一个正方形的方框内,没不是单独的,请各位高手多多帮忙,兄弟感激不尽.谢谢!using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace yixingtu
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private Region BmpRgn(Bitmap Picture, Color TransparentColor)
{
int nWidth = Picture.Width;
int nHeight = Picture.Height;
Region rgn = new Region(); rgn.MakeEmpty(); bool isTransRgn;//前一个点是否在透明区
Color curColor;//当前点的颜色
Rectangle curRect = new Rectangle();
curRect.Height = 1; int x = 0, y = 0; //逐像素扫描这个图片,找出非透明色部分区域并合并起来。 for (y = 0; y < nHeight; ++y)
{
isTransRgn = true; for (x = 0; x < nWidth; ++x)
{
curColor = Picture.GetPixel(x, y); if (curColor == TransparentColor || x == nWidth - 1)//如果遇到透明色或行尾
{
if (isTransRgn == false)//退出有效
{
curRect.Width = x - curRect.X;
rgn.Union(curRect);
}
}
else//非透明色
{
if (isTransRgn == true)//进入有效区
{
curRect.X = x;
curRect.Y = y;
} }//if curColor isTransRgn = curColor == TransparentColor; }//for x
}//for y return rgn;
}
private void Form1_Load(object sender, EventArgs e)
{
} private void button1_Click(object sender, EventArgs e)
{
this.Region = BmpRgn(new Bitmap("d:\\a.gif"), Color.FromArgb(0, 0, 0));
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace yixingtu
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private Region BmpRgn(Bitmap Picture, Color TransparentColor)
{
int nWidth = Picture.Width;
int nHeight = Picture.Height;
Region rgn = new Region(); rgn.MakeEmpty(); bool isTransRgn;//前一个点是否在透明区
Color curColor;//当前点的颜色
Rectangle curRect = new Rectangle();
curRect.Height = 1; int x = 0, y = 0; //逐像素扫描这个图片,找出非透明色部分区域并合并起来。 for (y = 0; y < nHeight; ++y)
{
isTransRgn = true; for (x = 0; x < nWidth; ++x)
{
curColor = Picture.GetPixel(x, y); if (curColor == TransparentColor || x == nWidth - 1)//如果遇到透明色或行尾
{
if (isTransRgn == false)//退出有效
{
curRect.Width = x - curRect.X;
rgn.Union(curRect);
}
}
else//非透明色
{
if (isTransRgn == true)//进入有效区
{
curRect.X = x;
curRect.Y = y;
} }//if curColor isTransRgn = curColor == TransparentColor; }//for x
}//for y return rgn;
}
private void Form1_Load(object sender, EventArgs e)
{
} private void button1_Click(object sender, EventArgs e)
{
this.Region = BmpRgn(new Bitmap("d:\\a.gif"), Color.FromArgb(0, 0, 0));
}
}
}
如果只是满足你开始说的要求的话,是不是可以考虑:
1. 做一个没有边框的Form
2. Form的TransparencyKey属性设置为你指定的颜色(可以在设计器里设,也可以用编码动态设)。
3. 放一个PictureBox。把小球的图片加载上。
4. 调整合适的大小。然后不就OK了?
http://so.blogchinese.com/06042/202595/archives/2006/200642518142.html
http://topic.csdn.net/t/20060322/17/4632557.html
TO wartim
你给我的网站代码和我贴出来一样,但是就是结果是圆在方框里面.
TO wanghui0380
你说的的见面我看了,和我要求不同.