|
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
|
|
|
|
|
Is there any mathod to transfer bulky data One to another DB as like BulkCopy.....?
|
|
|
|
|
If the databases are both Sql Server (and maybe some others) you can use an INSERT/SELECT statement.
You can get a DataReader from the source database, and perform inserts on the destination database.
If you do it enough you can write a Windows Service to copy the data. I've had to do that in the past for a data warehousing project.
|
|
|
|
|
Hi.
I'm facing very frustrated problam.
The code is little long so i'll try to describe:
1. I have object (entity) called MyObj , and one of it's members is array of 'int' type, and called "intArr".
2. Collection List<MyObj> .
3. DAL project to manage the list.
4. In the 'main' class i have variable which is also array of 'int' type, and called "intArr".
this variable passed as parameter to function in the DAL project, to create new "MyObj" and add it to the List.
The problam:
When the variable "intArr" in the main changed, it's effected immidiately on the MyObj.intArr.
I thought that both, reference to the same 'intArr'. possible?
|
|
|
|
|
Yes, this is the reason: an array of int is treated as an object and is assigned "by reference".
If what you what is a "deep copy" of the array you should code it explicitly.
class MyObj
{
...
public void DoSomething(int [] intArr)
{
this.intArr = intArr.Clone();
}
...
}
|
|
|
|
|
Thanks. It helps.
Just needed "casting" as int
class MyObj
{
...
public void DoSomething(int [] intArr)
{
this.intArr = intArr.Clone() as int[];
}
...
}
Quote Selected Text
|
|
|
|
|
I have a program that is running on a kiosk. I'm using the Shockwave dll to play flash files. It appears as if the more complex the flash file is (more action script) there's a memory leak until eventually the program crashes. This program has the flash player on the screen and loads file after file without closing down. So if it's not really releasing all of the memory, which is what it appears to be doing, how can I clear out the memory?
If need be what I would do is after playing a file, I would destroy the object, cleanup the memory and then create a new one.
In looking around the web, I have not yet been able to find how to destroy the object, clean up the memory and then recreate the object.
Can somebody please help?
Thanks.
Jeff.
|
|
|
|
|
Effectively, have 2 instances running - when one is finished with unload it and load a new instance in a new app domain and show the background instance in place.
|
|
|
|
|
I don't understand what you mean by unload it and load a new instance. Do you mean unload the whole program? There is other stuff going on on the screen. The flash player is only part of what is visible on the screen.
Jeff.
|
|
|
|
|
No - I was thinking you'd have the Flash part in a separate AppDomain - you could overlay this over the top by controlling the Z Order. Release the App Domain, and reclaim the memory.
|
|
|
|
|
What do you mean by AppDomain?
BTW - don't know if it matters this is a Windows App.
J.
|
|
|
|
|
Are you using .NET (you should be if you are posting in the C# forum)? Look up Application Domains.
|
|
|
|
|
Pete,
I'm still trying to solve this. I'm using C# .Net 1.1 (Don't ask!) on a Windows App.
Any help would be greatly appreciated.
Jeff.
|
|
|
|