|
shekhar258395 wrote: how can i convert an color image in to black & white
Lots of example here[^]
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
If your pictures are small you can try the code below, but its performance poor.
public Image BW(Bitmap bmp)
{
for (int i = 0; i < bmp.Width; i++)
{
for (int j = 0; j < bmp.Height; j++)
{
int hede = (bmp.GetPixel(i, j).R + bmp.GetPixel(i, j).G + bmp.GetPixel(i, j).B) / 3;
bmp.SetPixel(i, j, Color.FromArgb(hede, hede, hede));
}
}
return bmp;
}
Instead of using this method try to google for an algorithm
|
|
|
|
|
I need help on how to develop an sms web portal
|
|
|
|
|
Try this: www.ozekisms.com
|
|
|
|
|
Hi all,
I have a generic class internal static class Singleton<T> where T : class . Within the class I declare the following private field private static T _instance; .
Within the generic class contructor I perform the following actions:
Type type = typeof(T);
BindingFlags searchPattern = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
ConstructorInfo constructor = type.GetConstructor(searchPattern, null, Type.EmptyTypes, null);
if (constructor == null)
{
string errorMsg = String.Format("The type {0} does not have a default constructor.", type.FullName);
throw new ArgumentNullException(errorMsg);
}
_instance = (T)constructor.Invoke(new object[0]);
To make use of the class I perform the following line of code:
Singleton < ApplicationProtector > ...
The class ApplicationProtector has a static field within it called expType which is a enum.
How can I make use of this static field expType after creating the instance of the object in the generic class (only when actually running the application and debugging it, can I see the field value which foems part of the _instance ):
<br />
...<br />
_instance = (T)constructor.Invoke(new object[0]);<br />
...
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
er...
ApplicationProtector.expType - the same way you would always reference a static member.
Am I missing something?
|
|
|
|
|
er ... ??
Thanks for the response but....
internal static class Singleton<T> where T : class
{
private static T _instance;
static Singleton()
{
Type type = typeof(T);
BindingFlags searchPattern = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
ConstructorInfo constructor = type.GetConstructor(searchPattern, null, Type.EmptyTypes, null);
if (constructor == null)
{
string errorMsg = String.Format("The type {0} does not have a default constructor.", type.FullName);
throw new ArgumentNullException(errorMsg);
}
_instance = (T)constructor.Invoke(new object[0]);
}
}
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
Forget about generics, by trying to use an enum defined in that class where you're trying to use it, you've defeated the purpose of your generic singleton wrapper!
What are you trying to achive? The class you've defined should be totally agnostic of the T passed it. It should not need to access any enum in one of the classes. All it should do is attempt to instantiate any class which can be used as a singleton.
|
|
|
|
|
|
First thing i'd do if I were you is go and read up on the singleton design pattern. The class you have found/written is for that purpose, and that purpose alone. You may have accidentally stumbled upon a tried-and-tested pattern of software design. Thats usually how you come accross such things and will make you a better programmer.
In answer to your question, you would use the fields/methods of your class as follows - assume the "T" passed in is the class MyClass which has an instance method void Foo() and an instance property int Bar .
Singleton<MyClass> singleton = new Singleton<MyClass>();
singleton.Instance.Foo();
singleton.Instance.Bar = 5
Crucially, you would never access a static property/method on MyClass , only instance properties/methods. Thats by convention of course, as I stated originally there is nothing stopping you referencing a static member, MyClass.StaticProperty
|
|
|
|
|
I will keep that in mind. Many thanks for your patience and help.
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
It looks to me line you're doing something like this[^] and you could use the "new" constraint for that instead of reflection, are you?
|
|
|
|
|
Hi,
Thanks for the reply.
Well I am making use of reference type contraints and in the link they are making use of constructor type contraints, and making use of singleton = new T(); is not permitted when making use of reference type contraints: Cannot create an instance of the variable type 'T' because it does not have the new() constraint.
Either way making use of constructor type contraints does not allow me to gain usage to the other classes's field as in my example.
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
I think you're missing the point of what your Singleton class is for. Did you write it, did someone else write it, or did you get that code snippet from somewhere?
|
|
|
|
|
Hmmm ... OK, I am not trying to achieve a Singleton pattern. I have named my class in such a way that caused alot of confusion ... sorry about that.
Back to the drawing board for me with regards to generics ....
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
see answer above, there's no point posting the same response to me twice!
|
|
|
|
|
Looks like you read[^] this article.
No, only those members that are known to exist for type T are accessible. You only constrained T to class so only members of class are accessible.
If you write an interface IHaveAnExpType, apply it to your class, and then add it as a constraint you would have access to it.
P.S. Dynamic types in C# 4.0 may allow this sort of thing.
|
|
|
|
|
There is cs class that calls native DLL. That class is called from ASP.NET application. How can I step into native DLL while debugging the web project on my computer?
P.S. I can step into the DLL if I run any C# windows project.
Чесноков
|
|
|
|
|
Do not Post the same message twice
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
I can very easily extend the glass area of a normal form by calling the DwmExtendFrameIntoClientArea method. However I now have a requirement in which I need an MDI container/parent to have glass extended into the form. If the IsMdiContainer property is set to true, the part that is meant to be glass is white. Anybody have any experience with this issue?
|
|
|
|
|
See here[^] for the answer.
|
|
|
|
|
hi USE THE SAME API AND ADD TWO (ONE ON TOP AND ONE ON LEFT FOR NAVIGATION OR IF YOU JUST NEED ON TOP THEN ONLY ONE WILL WORK) PANELS TO MDIcONTAINER AND GIVE IT BACK COLOR AS bLACK AND IT WILL BE PAINTED AS GLASS BUT IN THE MDI APP YOU WILL LOOS GLASS ON ALL THE CHILD FORMS THATS WHERE I AM RIGHT NOW
|
|
|
|
|
Hi,
i'm in testing with the Process and ProcessStartInfo Classes.
But it doesn't work as aspected.
I want to run another application from my application withe the same rights, i mean with the same user name.
Any suggestions?
My Code:
ProcessStartInfo startinfo = new ProcessStartInfo();
startinfo.FileName = @"C:\Test.exe";
Process.Start( startinfo );
I tried to using the UserName Property, but it doesn't work, because i have to use the password also.
But i dont know the password of the actuall user. (Keyword: terminal Server)
But with the code like the example, the Apllication ist startet as SYSTEM.
Can anybody help me?
|
|
|
|
|
Hi.
How to insert date and time both in one column in oracle sql????
|
|
|
|
|
Do you want to know how to define the field, if so this[^] might be a better place to ask this question.
If you do mean programatically from C# then you really shoud first tell us what you're trying.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|