如何在windows mobile中使背景图像透明?

时间:2010-09-25 09:42:48

标签: c# windows-mobile transparency background-image

我正在用C#开发智能设备应用程序。我是windows mobile的新手。我已使用以下代码将背景图像添加到我的应用程序中的表单。我想让这个图像透明,以便我的窗体上的其他控件能够正确显示。

protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Bitmap CreateCustomerImage = new Bitmap(@"/Storage Card/background.png");
            e.Graphics.DrawImage(CreateCustomerImage, 0, 0);
        }

背景图片为蓝色。当应用程序运行标签,文本框和控件等控件时其他控件以白色显示。如何解决这个问题呢?您能否提供我可以解决上述问题的任何代码或链接?

1 个答案:

答案 0 :(得分:2)

如果你想让你的控件透明或者是一个图像,我无法弄清楚,但如果你想在这里绘制透明图像的方式是透明的。

您需要将特定像素设置为透明色,因为Windows Mobile不“本机”支持它。您需要创建在绘制图像时使用的ImageAttributes实例。下面的示例使用左上角的像素作为“透明色”。

private readonly ImageAttributes imgattr;
.ctor() {
    imgattr = new ImageAttributes();
    Color trns = new Bitmap(image).GetPixel(0, 0);
    imgattr.SetColorKey(trns, trns);
}

protected override void OnPaint(PaintEventArgs e) {
    e.Graphics.DrawImage(image,
                         new Rectangle(0, 0, Width, Height),
                         0, 0, image.Width, image.Height,
                         GraphicsUnit.Pixel,
                         imgattr);
}
相关问题