Re: Nearest colour problem



On 9 Jan, 17:12, Tadzzzio <pepit...@xxxxxxxxx> 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

.



Relevant Pages

  • OT: invisibility cloak
    ... beyond the OLED layer, ... you have essentially a really big and flexible lenticular display (this part ... could be made into a type of suit). ... otherwise "dead" areas of pixels for the flex sensors. ...
    (comp.arch)
  • Re: Pixel policy
    ... In reality most screens sold are actually Class 2 compliant but ... right by the definition of the standard to expect a Class 1 screen. ... There might not be but a display advertised as compliant with ISO 13406-2 ... expect it not to contain dead or lit pixels. ...
    (uk.tech.digital-tv)
  • Re: clarity of projected enlarged dicom films
    ... running a 1280x1024 display resolution to get full resolution display, ... this implies you're displaying 1024 pixels over linear distance 301 mm ... inches per pixel) on the flat panel monitor. ... Some of this is the projector ...
    (comp.protocols.dicom)
  • Re: DSLR versus P&S
    ... zoom, more realistically 50% zoom. ... Even these reduced zooms exaggerate the issue, since display pixels are ... Thus my normal practice is to assess images on screen at no more than ...
    (rec.photo.digital)