|
From: pepito72 on 9 Jan 2008 10:51 Hi A problem with trying to find the nearest colour. I have an image which I use GetPixel to return the colour of various points. However .... not all colours returned will be a System/Known/Pre- defined colour. So they wont have corresponding names - this is a problem because my app needs to return the colour name of each pixel. So I have looked at GetNearestColor but this just seems to return the original color I passed it in the first place!? Any pointers would be appreciated. Thanks Tad
From: Jan Hyde (VB MVP) on 9 Jan 2008 11:18 pepito72(a)gmail.com's wild thoughts were released on Wed, 9 Jan 2008 07:51:25 -0800 (PST) bearing the following fruit: >Hi > >A problem with trying to find the nearest colour. I have an image >which I use GetPixel to return the colour of various points. >However .... not all colours returned will be a System/Known/Pre- >defined colour. So they wont have corresponding names - this is a >problem because my app needs to return the colour name of each pixel. >So I have looked at GetNearestColor but this just seems to return the >original color I passed it in the first place!? > >Any pointers would be appreciated. > >Thanks >Tad First decide which language you are working in. You've posted (multiposted no less) this to at least VB6 and VB.Net groups. -- Jan Hyde https://mvp.support.microsoft.com/profile/Jan.Hyde
From: Tadzzzio on 9 Jan 2008 12:12 On 9 Jan, 17:18, "Jan Hyde (VB MVP)" <StellaDrin...(a)REMOVE.ME.uboot.com> wrote: > pepit...(a)gmail.com's wild thoughts were released on Wed, 9 > Jan 2008 07:51:25 -0800 (PST) bearing the following fruit: > > >Hi > > >A problem with trying to find the nearest colour. I have an image > >which I use GetPixel to return the colour of various points. > >However .... not all colours returned will be a System/Known/Pre- > >defined colour. So they wont have corresponding names - this is a > >problem because my app needs to return the colour name of each pixel. > >So I have looked at GetNearestColor but this just seems to return the > >original color I passed it in the first place!? > > >Any pointers would be appreciated. > > >Thanks > >Tad > > First decide which language you are working in. You've > posted (multiposted no less) this to at least VB6 and VB.Net > groups. > > -- > Jan Hyde > > https://mvp.support.microsoft.com/profile/Jan.Hyde Sorry ...forgot to say .... I am using VB 2008 Express.
From: Auric__ on 9 Jan 2008 12:29 On Wed, 09 Jan 2008 17:12:59 GMT, Tadzzzio wrote: > On 9 Jan, 17:18, "Jan Hyde (VB MVP)" > <StellaDrin...(a)REMOVE.ME.uboot.com> wrote: >> pepit...(a)gmail.com's wild thoughts were released on Wed, 9 >> Jan 2008 07:51:25 -0800 (PST) bearing the following fruit: >> >> >Hi >> >> >A problem with trying to find the nearest colour. �I have an >> >image which I use GetPixel to return the colour of various >> >points. However .... not all colours returned will be a >> >System/Known/Pre- defined colour. �So they wont have >> >corresponding names - this is a problem because my app needs to >> >return the colour name of each pixel. So I have looked at >> >GetNearestColor but this just seems to return the original color >> >I passed it in the first place!? >> >> >Any pointers would be appreciated. >> >> >Thanks >> >Tad >> >> First decide which language you are working in. You've >> posted (multiposted no less) this to at least VB6 and VB.Net >> groups. >> >> -- >> Jan Hyde >> >> https://mvp.support.microsoft.com/profile/Jan.Hyde > > Sorry ...forgot to say .... I am using VB 2008 Express. Then you should stick with a .Net group. -- Java: "write once, run anywhere" = "write once, debug everywhere"
From: Mike Williams on 9 Jan 2008 14:04
On 9 Jan, 17:12, Tadzzzio <pepit...(a)gmail.com> wrote: > Sorry ...forgot to say .... I am using > VB 2008 Express. As Auric has already mentioned, you're in the wrong newsgroup. However, as a piece of general information about the GetNearestColor API (which applies in both cases) it was not designed to perform the job you want it to do. All it does (or used to do!) is return the nearest colour which the specified device can actually display, which of course on displays running at full colour depth will always be exactly the same as the colour value you pass to it. I don't think the function is much use these days anyway, even for that task, because it doesn't seem to work and more. As far as I recall it used to return the nearest "solid colour" the device could display (at least it definitely did so on my old Win98 system), so that if for example you were running a 16 bit colour depth display and passed it the RGB colour value 13, 13, 13 it would return the RGB value 8, 12, 8 as being the nearest solid colour (on a rounding down basis) that the screen could display (green typically has a higher resolution that red and blue on 16 bit displays because it normally uses 6 of the available 16 bits whereas red and blue use 5 each, which is why the green component in the above example is different to the red and blue components). However, I noticed some time ago when I changed OS (or machine, I can't remember) it started returning exactly the same value as the colour you passed to it, even on 16 bit displays. At the time I put this down to the possibility that the routine had been changed so as to return the "colour it can mix" to produce the desired colour, which seemed to be verified by the fact that my machine at that time actually did display a bit pattern of differently coloured pixels when you drew a solid block in the desired colour, with the individual pixels mixing quite neatly to produce the overall colour. I changed my mind on that point though when I later noticed (again I think when I changed to XP, but I can't remember now) that the system did not mix pixels in that way to produce the desired overall colour anyway, and instead just produced a solid block of colour where every pixel in the block was exactly the same colour (each pixel being 8, 12, 8 in the above example value of 13, 13, 13 on a 16 bit display). So, even when run on a 16 bit display system the GetNearestColour API simply returned the exact value you passed to it (for example if you passed 13, 13, 13 then you got 13, 13, 13 back as a result on a 16 bit display, even though the solid colour produced in a block actually when you asked for 13, 13, 13 consisted of pixels where every single pixel in the block was the colour 8, 12, 8), which of course makes it totally useless! So, at least from my own experience, GetNearestColor seems to be a complete waste of time! In my experience the most reliable way to get the nearest solid colour these days is to use SetPixel to set a single pixel to the value you require (13, 13, 13 in the above example) and then use GetPixel to read the actual colour value of that pixel, which will return 8, 12, 8 on most 16 bit displays. In that way you can actually get the "nearest solid colour" available on the display. I imagine that VB.Net (which you are using) has native functions for this stuff in system.drawing or whatever it uses, and I don't know whether the VB.Net implementation of the equivalent to the GetNearestColor API behaves as above or not, but it might be worth checking out the system.drawing stuff (or whatever it is called). I mention all this merely as an interesting side note though, because your own requirement seems to be something quite different (getting the nearest system colour with a predefined colour name to a given colour value?) and of course I cannot help you with that because any code I come up with in VB6 simply will not work in VB.Net. Mike |