PC Review


Reply
Thread Tools Rate Thread

(Color myColor = Color.LightBlue) returns value RGB{0x0}???

 
 
Sami
Guest
Posts: n/a
 
      27th Jan 2005
Hello,
I just started out with Windows.Forms and was going through the MS
tutorials.
In the tutorial where you can create a non-rectangular shaped window by
using your own window painted with some paint utility, I am having some
problems with trying to compare the color of the pixel that I retrieve using
Bitmap.GetPixel(...) method.

My pseudo-code looks like this:
****************************************************************************
******
OnMouse_Click(...)
{
Color myColor = Bitmap.GetPixel(e.X, e.Y);
Color colorToCompare = Color.LightBlue; // At this point I notice
that the colorToCompare variable has a value of RGB{0x0}???!!! why?

if (myColor == colorToCompare)
// then execute logic which never does.
}
****************************************************************************
*******

I have another question. The reason I am trying to get the color of the
pixel is because I want to allow a mousemove event only when the user clicks
the mouse on the visible region of my form and not on its transparent
background. But I still have the problem that when a user clicks on the
transparent background of my window the icons (e.g.) that I see on that
position are not chosen? How can I choose the background items on a desktop
or if there is another application on the background when a user clicks on
the transparent background of my form?
--
Regards,
Sami

[Remove Numbers from e-mail address to use it]


 
Reply With Quote
 
 
 
 
Morten Wennevik
Guest
Posts: n/a
 
      27th Jan 2005
Hi Sami,

There are two possible solutions for the colors not being equal.
1: myColor isn't LightBlue
2: myColor has a different alpha value than 255, which it probably might
if the image contains transparent parts.

To ignore the alpha value you can just check for

if(myColor.R == colorToCompare.R && myColor.G == colorToCompare.G &&
myColor.B == colorToCompare.B)
{
//the colors are sort of the same
}

As for the second question, I never had a problem with clicking on a
transparent part of my form not falling through. Not sure what kind of
transparency you are using, try setting the form's TransparencyKey
property to the same color as the form's backcolor. Use the same
backcolor for your image's Transparency (I never tried transparent forms
with bitmaps though, so I'm not sure they would work).


On Thu, 27 Jan 2005 10:51:16 +0100, Sami <(E-Mail Removed)>
wrote:

> Hello,
> I just started out with Windows.Forms and was going through the MS
> tutorials.
> In the tutorial where you can create a non-rectangular shaped window by
> using your own window painted with some paint utility, I am having some
> problems with trying to compare the color of the pixel that I retrieve
> using
> Bitmap.GetPixel(...) method.
>
> My pseudo-code looks like this:
> ****************************************************************************
> ******
> OnMouse_Click(...)
> {
> Color myColor = Bitmap.GetPixel(e.X, e.Y);
> Color colorToCompare = Color.LightBlue; // At this point I notice
> that the colorToCompare variable has a value of RGB{0x0}???!!! why?
>
> if (myColor == colorToCompare)
> // then execute logic which never does.
> }
> ****************************************************************************
> *******
>
> I have another question. The reason I am trying to get the color of the
> pixel is because I want to allow a mousemove event only when the user
> clicks
> the mouse on the visible region of my form and not on its transparent
> background. But I still have the problem that when a user clicks on the
> transparent background of my window the icons (e.g.) that I see on that
> position are not chosen? How can I choose the background items on a
> desktop
> or if there is another application on the background when a user clicks
> on
> the transparent background of my form?




--
Happy Coding!
Morten Wennevik [C# MVP]
 
Reply With Quote
 
Sami
Guest
Posts: n/a
 
      27th Jan 2005
Hello,
Thanks for the prompt reply.
I might not have been very clear.

My first question was why I get a value of RGB{0x0} for Color.LightBlue (or
any other colour for that matter). Shouldn't it give me a valid RGB value?

As for the second question, I still don't understand your answer.
I am using a non-rectangular bitmap as the background for my form. Then I
set the Transparency Key Property of my form to the same colour as the
background colour of my bitmap image. By default I don't fall through. e.g.
if I have my form directly on top of the desktop I am able to see other app
icons through the transparent background of my form but am unable to start
the apps by double-clicking on them which makes sense since I didn't tell my
code to do that. How would I do that programmatically?

--
Regards,
Sami

[Remove Numbers from e-mail address to use it]
"Morten Wennevik" <(E-Mail Removed)> schrieb im Newsbeitrag
newspsk9bd8ygklbvpo@pbn_computer...
> Hi Sami,
>
> There are two possible solutions for the colors not being equal.
> 1: myColor isn't LightBlue
> 2: myColor has a different alpha value than 255, which it probably might
> if the image contains transparent parts.
>
> To ignore the alpha value you can just check for
>
> if(myColor.R == colorToCompare.R && myColor.G == colorToCompare.G &&
> myColor.B == colorToCompare.B)
> {
> //the colors are sort of the same
> }
>
> As for the second question, I never had a problem with clicking on a
> transparent part of my form not falling through. Not sure what kind of
> transparency you are using, try setting the form's TransparencyKey
> property to the same color as the form's backcolor. Use the same
> backcolor for your image's Transparency (I never tried transparent forms
> with bitmaps though, so I'm not sure they would work).
>
>
> On Thu, 27 Jan 2005 10:51:16 +0100, Sami <(E-Mail Removed)>
> wrote:
>
> > Hello,
> > I just started out with Windows.Forms and was going through the MS
> > tutorials.
> > In the tutorial where you can create a non-rectangular shaped window by
> > using your own window painted with some paint utility, I am having some
> > problems with trying to compare the color of the pixel that I retrieve
> > using
> > Bitmap.GetPixel(...) method.
> >
> > My pseudo-code looks like this:
> >

****************************************************************************
> > ******
> > OnMouse_Click(...)
> > {
> > Color myColor = Bitmap.GetPixel(e.X, e.Y);
> > Color colorToCompare = Color.LightBlue; // At this point I notice
> > that the colorToCompare variable has a value of RGB{0x0}???!!! why?
> >
> > if (myColor == colorToCompare)
> > // then execute logic which never does.
> > }
> >

****************************************************************************
> > *******
> >
> > I have another question. The reason I am trying to get the color of the
> > pixel is because I want to allow a mousemove event only when the user
> > clicks
> > the mouse on the visible region of my form and not on its transparent
> > background. But I still have the problem that when a user clicks on the
> > transparent background of my window the icons (e.g.) that I see on that
> > position are not chosen? How can I choose the background items on a
> > desktop
> > or if there is another application on the background when a user clicks
> > on
> > the transparent background of my form?

>
>
>
> --
> Happy Coding!
> Morten Wennevik [C# MVP]



 
Reply With Quote
 
Sami
Guest
Posts: n/a
 
      27th Jan 2005
Another question that i have is whether there is any way to obtain the
PixelColor without using the Bitmap object?
e.g. How would I obtain the pixel color on a point on a form if I am not
using any bitmaps as the background image on a form.

--
Regards,
Sami

[Remove Numbers from e-mail address to use it]
"Sami" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
> Hello,
> I just started out with Windows.Forms and was going through the MS
> tutorials.
> In the tutorial where you can create a non-rectangular shaped window by
> using your own window painted with some paint utility, I am having some
> problems with trying to compare the color of the pixel that I retrieve

using
> Bitmap.GetPixel(...) method.
>
> My pseudo-code looks like this:
>

****************************************************************************
> ******
> OnMouse_Click(...)
> {
> Color myColor = Bitmap.GetPixel(e.X, e.Y);
> Color colorToCompare = Color.LightBlue; // At this point I notice
> that the colorToCompare variable has a value of RGB{0x0}???!!! why?
>
> if (myColor == colorToCompare)
> // then execute logic which never does.
> }
>

****************************************************************************
> *******
>
> I have another question. The reason I am trying to get the color of the
> pixel is because I want to allow a mousemove event only when the user

clicks
> the mouse on the visible region of my form and not on its transparent
> background. But I still have the problem that when a user clicks on the
> transparent background of my window the icons (e.g.) that I see on that
> position are not chosen? How can I choose the background items on a

desktop
> or if there is another application on the background when a user clicks on
> the transparent background of my form?
> --
> Regards,
> Sami
>
> [Remove Numbers from e-mail address to use it]
>
>



 
Reply With Quote
 
=?ISO-8859-2?Q?Marcin_Grz=EAbski?=
Guest
Posts: n/a
 
      27th Jan 2005
Hi Sami,

> Another question that i have is whether there is any way to obtain the
> PixelColor without using the Bitmap object?
> e.g. How would I obtain the pixel color on a point on a form if I am not
> using any bitmaps as the background image on a form.


The "GetPixel" is a method of "Bitmap" class so you cannot use
it without "Bitmap" instance.
Some time ago i found a way to copy form (image) into the Bitmap,
but that solution needs "DllImport" of gdi32.dll.

HTH
Marcin
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
custom color for font color and or background shading color Ben Microsoft Excel Programming 2 5th May 2010 02:32 PM
color transition (color changes from dark color to light color) color transition Microsoft Powerpoint 2 21st Nov 2009 12:21 PM
selection.font.color returns wrong color; the first execution AnExpertNovice Microsoft Excel Programming 14 7th Feb 2006 12:30 PM
AIO color & BW print, color & BW copy, pcfax, color scan A. L. Shaw, MD Printers 2 14th Jan 2006 04:44 AM
(Color myColor = Color.LightBlue) returns value RGB{0x0}??? Sami Microsoft C# .NET 4 27th Jan 2005 11:05 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:16 PM.