transparent image

M

MS

Hi all,
I create a 800*500 offscreen bitmap and want to make it to transpaency.
But it failed.

Here is my testing code.
----------------------------------------------------------------------------
-----------------------------------------------
private Bitmap offBitmap = null;
private ImageAttributes imgAtt = new ImageAttributes();
private void Form1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
Graphics g;
Rectangle rt = new Rectangle(0, 0, 800, 500);
if (this.offBitmap == null)
{
this.offBitmap = new Bitmap(800, 500);
}
g= Graphics.FromImage(this.offBitmap);
g.Clear(Color.FromArgb(255, 0, 255));
Pen pen = new Pen(Color.Pink);
g.DrawLine(pen, 0, 0, 800, 500);
pen.Dispose();
g.Dispose();
imgAtt.SetColorKey(Color.FromArgb(255, 0, 255),
Color.FromArgb(255,0,255));
e.Graphics.DrawImage(this.offBitmap, rt, 0, 0, 800, 500,
GraphicsUnit.Pixel, this.imgAtt);
imgAtt.ClearColorKey();
}

Thanks in advance.

Luyun
 
R

RAVI KRISHNASWAMY [MSFT]

Luyun, I compiled and ran your code against our bits and it seems to work
just fine (there has not been any change in this functionality between V1
and SP1). All I am seeing is the pink line that is drawn across the Form.
What exactly is that not working for you? can you attach a bitmap? Can you
also give the exact configuration details (such as the device, NETCF
version etc) where it is not working?

Thanks
-R

This posting is provided "AS IS" with no warranties, and confers no rights.
 
L

Luyun

If I executed this program on Windows CE.NET emulator, it worked fine.
But If I ran this program on my device, it shown transparent color
(255,0,255) as background color.
That means, I saw the transparent color on Form.
My device is NS handheld (x86) platform with Windows CE.NET 4.1
and the .NET compact framework version is 1.0.5000.

Thanks for your reply.
Luyun
 
S

Serg Kuryata [MS]

Hello Luyun,

The reason why the program works on Windows CE.NET emulator and it does not
work on the real device is the difference in color depth between the
emulator and the real device. On the emulator that color depth is at least
24 bits but color depth of a real device's screen usually does not exceed
16 bits. As a result, when you use color (255, 0, 255) to fill the
background of a bitmap on the emulator, the system fills the bitmap with
the specified color (255, 0, 255) and everything works fine. When you run
the same code on a device, the system converts the specified color
according to the supported color depth. So, for example, on a device with
16 bits color depth the bitmap will be filled with color (248, 0, 248) -
the lowest 3 bits of the R value, 2 bits of the G value, and 3 bits of the
B value are truncated. That's why the bitmap is not drawn transparently.

Hope this helps.
Thank you,
Sergiy.

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Luyun" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: transparent image
| Date: Wed, 13 Aug 2003 11:34:49 +0800
| Lines: 28
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: 139.223.31.129
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:30826
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| If I executed this program on Windows CE.NET emulator, it worked fine.
| But If I ran this program on my device, it shown transparent color
| (255,0,255) as background color.
| That means, I saw the transparent color on Form.
| My device is NS handheld (x86) platform with Windows CE.NET 4.1
| and the .NET compact framework version is 1.0.5000.
|
| Thanks for your reply.
| Luyun
|
| "RAVI KRISHNASWAMY [MSFT]" <[email protected]> ¼¶¼g©ó¶l¥ó·s»D
| :[email protected]...
| > Luyun, I compiled and ran your code against our bits and it seems to
work
| > just fine (there has not been any change in this functionality between
V1
| > and SP1). All I am seeing is the pink line that is drawn across the
Form.
| > What exactly is that not working for you? can you attach a bitmap? Can
you
| > also give the exact configuration details (such as the device, NETCF
| > version etc) where it is not working?
| >
| > Thanks
| > -R
| >
| > This posting is provided "AS IS" with no warranties, and confers no
| rights.
| >
| >
|
|
|
 
L

Luyun

Hi Serg,
Thanks for your help. It seems work now. :)
I will do more testings on this.

BR,
Luyun
Serg Kuryata said:
Hello Luyun,

The reason why the program works on Windows CE.NET emulator and it does not
work on the real device is the difference in color depth between the
emulator and the real device. On the emulator that color depth is at least
24 bits but color depth of a real device's screen usually does not exceed
16 bits. As a result, when you use color (255, 0, 255) to fill the
background of a bitmap on the emulator, the system fills the bitmap with
the specified color (255, 0, 255) and everything works fine. When you run
the same code on a device, the system converts the specified color
according to the supported color depth. So, for example, on a device with
16 bits color depth the bitmap will be filled with color (248, 0, 248) -
the lowest 3 bits of the R value, 2 bits of the G value, and 3 bits of the
B value are truncated. That's why the bitmap is not drawn transparently.

Hope this helps.
Thank you,
Sergiy.

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Luyun" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: transparent image
| Date: Wed, 13 Aug 2003 11:34:49 +0800
| Lines: 28
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: 139.223.31.129
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:30826
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| If I executed this program on Windows CE.NET emulator, it worked fine.
| But If I ran this program on my device, it shown transparent color
| (255,0,255) as background color.
| That means, I saw the transparent color on Form.
| My device is NS handheld (x86) platform with Windows CE.NET 4.1
| and the .NET compact framework version is 1.0.5000.
|
| Thanks for your reply.
| Luyun
|
| "RAVI KRISHNASWAMY [MSFT]" <[email protected]> ¼¶¼g©ó¶l¥ó·s»D
| :[email protected]...
| > Luyun, I compiled and ran your code against our bits and it seems to
work
| > just fine (there has not been any change in this functionality between
V1
| > and SP1). All I am seeing is the pink line that is drawn across the
Form.
| > What exactly is that not working for you? can you attach a bitmap? Can
you
| > also give the exact configuration details (such as the device, NETCF
| > version etc) where it is not working?
| >
| > Thanks
| > -R
| >
| > This posting is provided "AS IS" with no warranties, and confers no
| rights.
| >
| >
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top