日期:2014-05-17  浏览次数:20782 次

实现这样的效果怎么做呀
本帖最后由 flashposition 于 2013-09-21 19:36:20 编辑
需求是这样的:有很多线路,是不规则的线条,PNG格式,为了响应不透明部分也就是线条部分的鼠标事件,我记下了不透明部分的GraphicsPath 然后在MouseMove里判断,可是这GetTransparentBounds取GraphicsPath 非常的慢,我也是才接触GDI,也不知道思路对不对,像这样怎么实现?还有什么别的思路?

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        GraphicsPath gp1 = null;
        GraphicsPath gp2 = null;
        GraphicsPath gp3 = null;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Resize(object sender, EventArgs e)
        {
            Bitmap bit = new Bitmap(panel3.Width, panel3.Height);
            Graphics g = Graphics.FromImage(bit);
            g.Clear(Color.Transparent);
            g.DrawImage(Properties.Resources._1, 0, 0, panel3.Height, panel3.Width);
            gp1 = GetTransparentBounds(bit);

            g.Clear(Color.Transparent);
            g.DrawImage(Properties.Resources._2, 0, 0, panel3.Height, panel3.Width);
            gp2 = GetTransparentBounds(bit);

            g.Clear(Color.Transparent);
            g.DrawImage(Properties.Resources._3, 0, 0, panel3.Height, panel3.Width);
            gp3 = GetTransparentBounds(bit);

            g.DrawImage(Properties.Resources._1, 0, 0, panel3.Height, panel3.Width);
            g.DrawImage(Properties.Resources._2, 0, 0, panel3.Height, panel3.Width);