透明背景

绘制背景透明的图片,在有背景色的Form上显示透明图片,这是.NET CF本身提供的方法,关键是最后一个参数。

 

//在有背景色的Form上显示透明图片(事先准备背景透明的图片)
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Assembly asm = Assembly.GetExecutingAssembly();
            Bitmap backgroundImage = new Bitmap(asm.GetManifestResourceStream("MyControl.TransparentImg.13.png"));

            ImageAttributes attr = new ImageAttributes();
            attr.SetColorKey(backgroundImage.GetPixel(0, 0), backgroundImage.GetPixel(0, 0));


            e.Graphics.DrawImage(backgroundImage, new Rectangle(5, 5, 256, 256), 0, 0, 256, 256, GraphicsUnit.Pixel, attr);
        }

posted @   张兴业  阅读(193)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示