如何使Windows Mobile中的背景图像透明? [英] How to make the background image transparent in windows mobile?

查看:76
本文介绍了如何使Windows Mobile中的背景图像透明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C#开发智能设备应用程序.我是Windows Mobile的新手.通过使用以下代码,我将背景图像添加到了应用程序中的表单中.我想使该图像透明,以便Windows窗体上的其他控件将正确显示.

I am developing the smart device application in C#. I am new to the windows mobile. I have added the background image to the form in my application by using the following code. I want to make this image transparent so that other controls on my windows form will be displayed properly.

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

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

The background image has blue color. When the application runs the controls such as label, text box & other controls displayed in white color. How to solve this problem? Can you provide me any code or link through which I can solve the above issue?

推荐答案

我无法确定是否要使控件透明或图像,但是如果要在绘制图像时使图像透明,请按以下步骤操作.

I can't make out if you want to make your controls transparent or an image, but if you want to make an image transparent when drawing it here's how.

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

You need to set a particular pixel as the transparent color as Windows Mobile doesn't support it "natively". You need to create an ImageAttributes instance that you use when drawing the image. The example below uses the pixel in the upper left corner as the "transparent color".

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);
}

这篇关于如何使Windows Mobile中的背景图像透明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆