|
I'm afraid there is a fundamental flaw in your approach: JPEG images tend to be highly compressed, which means every pixel is approximated in such a way that fewer bits are required. Applying an equal-test on jpegged images does not make much sense. What you should do is allow for some deviation, say:
deviation=deltaRed*deltaRed+deltaGreen*deltaGreen+deltaBlue*deltaBlue
or similar in another color space (e.g. HSB).
Only when the deviation is large enough you should call the pixel "not blue".
BTW: why don't you use a normal 2D matrix, as in int[bitmapWidth, bitmapHeight]?
|
|
|
|
|
I have custom windows user control. It is just a textbox puted on a panel. And panel is on User control. The panel OnPaint is overriden.
Everything looks fine except when some form comes on the control or menu open on it and I move or close the above form, the user control looks does not refresh completely extra lines from closed form remain on the panel. Should I call Invalidate() or Refresh() from specific event of user control?
Thanks
Mazy
"This chancy chancy chancy world."
|
|
|
|
|
does your Paint handler contain a base.OnPaint() ?
|
|
|
|
|
Hello,
I use a ColorEdit control in my form ( as picture )
I need to analyse the case when the user choose a color from Custom tab which the color is represtend in RGB structure as I know
the problem that i need to translate this value (ie 245;245;220) to the color name (ie "beige") that i can save it after to use an other time by methode Color.FromName(name)
please can someone help me.
thank you
http://yfrog.com/63clipboard01kg[^]
|
|
|
|
|
You can use the FromArgb method and pass it the integer values. That would make converting it obsolete. Not all values can be converted to a name either so converting would mean omitting many possibilities.
V.
|
|
|
|
|
So when its unknown color (ie its choosed in custom tab and not exist in the array of known colors)
how can i get its name?
|
|
|
|
|
That's the thing, you can't. You should save it's RGB values, not the name.
V.
|
|
|
|
|
Think about it. 8 Red bits, 8 Green bits, 8 Blue bits. (and 8 alpha channel, but lets ignore those for a moment)
2^8 * 2^8 * 2^8 = 256 * 256 * 256 = 16,777,216 different colours.
Who do you think is going to name them all? The whole of the English language has less than 1 million words.
If you used each of them for a colour, you would still need French, and German, and Spanish, and Italian, and Manderin, and ...
Use the numbers, Luke!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
I do.
|
|
|
|
|
I was going to reply that I didn't remember proposing , but...
...then I read my post and realised what you were talking about.
I'm sure you meant to say:
Luc Pattyn wrote: [AsthmaticVoice] I do. [/AsthmaticVoice]
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
You can't, or at least you shouldn't.
All colornames map to a hex value (though not reliably), but not all hex color values map to a color name.
Additionally, different systems have different colornames.
|
|
|
|
|
Yeah, what they said.
If it was an easy task Microsoft would have provided it already.
I store (database, XML, etc.) the value as #AARRGGBB; it works.
|
|
|
|
|
Not sure why you want the # sign there? I can see the advantage of using hex, but then I'd do either 0xAARRGGBB or simply AARRGGBB.
|
|
|
|
|
Because HTML uses it. This keeps that common look and feel. I see that, and know that it's a color that has been serialized.
|
|
|
|
|
I see.
|
|
|
|
|
A quick and accurate solution for colors that actually have names:
Consider your color fields as a long (32 bit) unsigned int.
i.e., RGB(16,32,64) are actually the values (for three) of bytes.
Convert them so that each takes it's proper place in the long.
Find the value of the long for each of the named colors.
[How you decide to do this I leave as an exercise]
Then, create a switch with each of the known values as a case.
A default value catches the rest (convert to a sting "#rrggbb", for example)
Since this is C#, you can also do the reverse.
Other solution could involve you with the Color enum's.
Loads of ways to do this.
They can be built into a set of overloaded functions so you can make it even easier to convert from the RGB values to string and enum values.
Think of this as a viable (if not always the most efficient) pattern for many similar problems.
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "As far as we know, our computer has never had an undetected error." - Weisert | "If you are searching for perfection in others, then you seek dissappointment. If you are searching for perfection in yourself, then you seek failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
My Vote of one:
Did you bother to read the other posts? The chaps with the orange diamonds are pretty experience, and they say he shouldn't do it (reasons below) Your reply is very misleading because:
Balboos wrote: .... Convert RGB to long........
Find the value of the long for each of the named colors.
What about the longs that don't have named colors (which are the majority, there are > 16 million colours available)? Make one up? Find the closest (Now what do I do if it is exactly between to colors?)?
Normally I'd chalk this down to lack of experience, but several people have given clear reasons why it can't be done.
|
|
|
|
|
I was fairly sure his tongue was in his cheek.
|
|
|
|
|
Tongue in cheek only to the extent in "be careful what you ask for - you might get it".
- If he's getting colors from large color-maps, he's wasting his time.
- If he's getting colors from web-pages or Winforms, then the hit-rate would be quite acceptable, with the caveat that he shouldn't expect to pick out colors from within gradient like objects.
That's his problem - I just gave a general solution to mapping. He could use a dictionary, or any number of other mapping scenarios, so long as failed matches have a handler.
What care we beyond (rightly) pointing out how rarely it will be successful in the most generalized case?
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "As far as we know, our computer has never had an undetected error." - Weisert | "If you are searching for perfection in others, then you seek dissappointment. If you are searching for perfection in yourself, then you seek failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
Keith Barrow wrote: What about the longs that don't have named colors (which are the majority, there are > 16 million colours available)? Make one up? Find the closest (Now what do I do if it is exactly between to colors?)?
I'm not trying to be cynical, but, if you read my answer, I include:
A default value catches the rest (convert to a sting "#rrggbb", for example)
Personally, I don't take the 16+ million colors, and tiny subset which are actually given names, to be a reason "why it can't be done", but why it won't work well for the general case. It is a solution that will work "when it can". Another thought for consideration: although obviously of little-to-no-use for general color selection, such as an image, it would be quite useful for situations where the color set is usually limited, such as a web-page (yes, any RGB value can be specified, but typically, a fixed known value is selected viz-a-viz a custom color).
One might even consider the list of colors available in, for example, the .NET framework, as some indication that others think that a color listing is feasible. Yes, the directionality is changing, and thus, the mapping won't always work . . . but the resultant utility, or lack of it, is a decision for the original questioner to ponder.
The clear reasons (in your opinion) as to why it can't be done (as you put it) are only why it shouldn't be done.
Perhaps you were a bit harsh or overzealous in the criticism, or now, even more convinced of it. Still, I'll not vote you a one for the lambaste - you're entitled and all that.
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "As far as we know, our computer has never had an undetected error." - Weisert | "If you are searching for perfection in others, then you seek dissappointment. If you are searching for perfection in yourself, then you seek failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
Balboos wrote: Personally, I don't take the 16+ million colors, and tiny subset which are actually given names, to be a reason "why it can't be done", but why it won't work well for the general case.
Seeing as you are going to play semantic arguements, the OP asks to translate an RGB colour to a colorname, not return the hex value and in the vanishingly small set of sub-cases where there is a colorname return the one that macthes. Worse you accuse me of saying it can't be done, if you'd read my post I said "You can't, or at least you shouldn't," very different from just "You can't."
Balboos wrote: Perhaps you were a bit harsh or overzealous in the criticism, or now, even more convinced of it. Still, I'll not vote you a one for the lambaste - you're entitled and all that.
If you think that post was lambasting you, you haven't been here for very long other people would have been far more harsh. I do understand your post, I simply think you are wrong. Other people actually thought you were joking as your response was so bad. At least I outlined my reasons for voting you a 1 in the hope you might benefit from the points I and others put forward.
|
|
|
|
|
Hello,
I am having trouble using MEF to implement programming language packages into my IDE.
My classes in the Moonlite.Languages.DynamicLoading project (in the Implementation namespace) - LanguagePackageLoader, TextEditorCodeCompletionProviderLoader and TextEditorLanguageBindingLoader - their OnImportsSatisfied methods never get called.
I can't see what I'm doing wrong - I have my interfaces that my packages inherit, and the classes that inherit the interfaces export themselves using the correct contract names.
I have two CompositionContainers - one that I use in my Program class that is used to find dialog window extensions, and one that I use in my CompositionInitializer class that is used for the language packages. The first CompositionContainer also loads the assemblies that are supposed to be loaded and used by the second one, and creates parts for them - could this be the problem?
The files you want to look at are the following:
http://code.google.com/p/moonlite-map-studio/source/browse/trunk/moonlite-map-studio/Moonlite/Program.cs
http://code.google.com/p/moonlite-map-studio/source/browse/trunk/moonlite-map-studio/Moonlite/Shell.cs
http://code.google.com/p/moonlite-map-studio/source/browse/#svn/trunk/moonlite-map-studio/Moonlite.Languages.DynamicLoading - that is the whole project that contains the dynamic language package loading.
Language package .dlls:
http://code.google.com/p/moonlite-map-studio/source/browse/#svn/trunk/moonlite-map-studio/Moonlite.Languages.Packages.Andromeda
http://code.google.com/p/moonlite-map-studio/source/browse/#svn/trunk/moonlite-map-studio/Moonlite.Languages.Packages.vJass
Any help is appreciated.
Thanks,
Theo
|
|
|
|
|
No one is going to download your code to figure out what you may done wrong. If you want help post a snippet here.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I never said anything about downloading anything; the files are online through subversion, so your "code snippets" are at those URLs.
|
|
|
|
|
You give a URL to a file so people expect that it will download said file. However, the same point applies. No one is going to want to visit an external link to view all of your code. Some access CP at work with restrictive firewalls or corporate policies that prevent it. Others simply don't want to. How many answers have you had so far?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|