|
Yepp, it probably can:
You need to split this up into different "filters".
The first thing you will need is a "Replace selected color" filter, which should replace one color with another. You could determine the "new" color using your logic, just like you calculated the "new" values for your pixels, just that you dont do this to every pixel in the picture, but only those that have exactly the same color values.
The second filter extends the first: "Replace colors", which should replace all colors in a certain range (e.g. "R245 to R255") with a given color (or simply "swap" R for B or something similar). In that case, you select one pixel, give a certain "range" (eg. +-10) and then select a "replace method" (so you can provide different methods).
Third would be a "grayscale replace" in which you split RGB channels and treat each channel seperately.
The fourth and last filter I can imagine is a RGB Filter. That means, my simply choosing a color (Red, Green or Blue) to remove, the image would be treated as a whole. You could (again) simply "split" the image and then only recombine G and B, with Red set to a "standard value" (e.g. 0) which then would yield a "red-free" version of your image.
Cheers
Sid
|
|
|
|
|
Hi,
I think this will not works becoz here as this is four layer filteration the performance gets effected tremandusly,but if you give some less layer filter but effective than it's good.
|
|
|
|
|
G'day folks,
well i am attempting to get an understanding on how to create the menuitems in a context menu on the fly. So far I have managed to actually achieve the menu items being created for the context menu. However, I have stumbled across one problem. Which is that how does one go about enhancing the event handler for the context menu to invoke individual actions for each of the menu items.
I have included a snippet of my code. In this sample example, I created a button, which essentially adds 4 menu items based on strArray to the context menu. Any recommendations on how to improve the context menu event handler so that when I click on menu item "A" in the context menu, the message box pops up.
Any recommendations will be appreciated.
thanks in advance.
string[] strArray = {"A", "B","C","D"}; //declared as global
private void contextMenu1_Popup(object sender, System.EventArgs e)
{
try
{
MenuItem miClicked = (MenuItem)sender;
string item = miClicked.Index.ToString();
switch(item)
{
case "A":
MessageBox.Show("A");
break;
case "B":
MessageBox.Show("B");
break;
case "C":
MessageBox.Show("C");
break;
case "D":
MessageBox.Show("D");
break;
}
}
catch
{}
}
//creating menuitems for context menu when the Push Button is pressed.
protected void button1_Click(object sender, EventArgs e)
{
for(int i=0;i
|
|
|
|
|
hehe, I know what you mean.
I used the following approach:
First, I extended the controls (in my case, buttons):
public class nodeButton : Button
{
private int index
// getter and setter go HERE
}
My "on-the-fly" generated controls are first stored into a control[]. At the same time the control is added to the array, I set the index-int to the controls index in the array.
I then have ONE event handler
nodeButton_Click
which is added to each nodeButton control at the same time the index is set.
Thus, using ((nodeButton)sender).index gives me information on which control has been clicked (and I can change the control accordingly).
so, lets say you created your controls and want to dispose of the control[] - no problem, each control is still referenced by the panel, form or whatever you use, with its unique index still intact, so you can find it again.
Just a few ideas
Sid
|
|
|
|
|
thanks for your feedback Sid. But I am still a bit confused. I was hoping you could give me another example bit simpler with code so that it can really sink in. Or even a link to a tutorial covers this topic.
thanks
|
|
|
|
|
This is how I would solve the problem. You still need to find a way to put your identifiers to some use.
I used this technique to load Plugins into a MenuItem and fire those events, with the user being able to freely change the item's menu position without having to re-assign events.
How that worked?
The user copies plugin dlls into the apps directory. each plugin has a GUID of some sort, which is used as the identifier on both the plugin and the item. This way, I can simply load the plugins up and let the user arrange them the way he needs them. I then simply look up the plugin via the identifier and let it do its stuff.
OK, some people will frown now. You are right, and it just occured to me as I read my explanation, that I am so freaking dumb.
This IS a solution to your described problem, but its totally crap for what I did. I was assuming that, as the Item Position changes when you modify MenuItem.Index, the associated handlers would somehow swich items. Bullshit. I never needed those, I just had to assing the plugin.dostuff to the appropiate MenuItem. NAAAAAAAAAAAAAAAAAARGH!
I guess I need more sleep
<br />
using System;<br />
using System.Drawing;<br />
using System.Windows.Forms;<br />
<br />
namespace contextdemo<br />
{<br />
public class MainForm : System.Windows.Forms.Form<br />
{<br />
private System.Windows.Forms.Panel panel1;<br />
private System.Windows.Forms.ContextMenu contextMenu1;<br />
private System.Windows.Forms.TextBox tbItems;<br />
private System.Windows.Forms.MenuItem menuItem1;<br />
private System.Windows.Forms.Button bCreate;<br />
public MainForm()<br />
{<br />
InitializeComponent();<br />
<br />
}<br />
<br />
[STAThread]<br />
public static void Main(string[] args)<br />
{<br />
Application.Run(new MainForm());<br />
}<br />
<br />
#region Windows Forms Designer generated code<br />
private void InitializeComponent() {<br />
this.bCreate = new System.Windows.Forms.Button();<br />
this.menuItem1 = new System.Windows.Forms.MenuItem();<br />
this.tbItems = new System.Windows.Forms.TextBox();<br />
this.contextMenu1 = new System.Windows.Forms.ContextMenu();<br />
this.panel1 = new System.Windows.Forms.Panel();<br />
this.SuspendLayout();<br />
this.bCreate.Location = new System.Drawing.Point(144, 160);<br />
this.bCreate.Name = "bCreate";<br />
this.bCreate.Size = new System.Drawing.Size(96, 24);<br />
this.bCreate.TabIndex = 2;<br />
this.bCreate.Text = "Create X Items";<br />
this.bCreate.Click += new System.EventHandler(this.BCreateClick);<br />
this.menuItem1.Index = 0;<br />
this.menuItem1.Text = "Standard Menu Item. Not generated.";<br />
this.menuItem1.Click += new System.EventHandler(this.standardMenuItem_Click);<br />
this.tbItems.Location = new System.Drawing.Point(32, 160);<br />
this.tbItems.Name = "tbItems";<br />
this.tbItems.Size = new System.Drawing.Size(88, 20);<br />
this.tbItems.TabIndex = 1;<br />
this.tbItems.Text = "5";<br />
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {<br />
this.menuItem1});<br />
this.panel1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255)));<br />
this.panel1.ContextMenu = this.contextMenu1;<br />
this.panel1.Location = new System.Drawing.Point(24, 32);<br />
this.panel1.Name = "panel1";<br />
this.panel1.Size = new System.Drawing.Size(144, 80);<br />
this.panel1.TabIndex = 0;<br />
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
this.ClientSize = new System.Drawing.Size(292, 237);<br />
this.Controls.Add(this.bCreate);<br />
this.Controls.Add(this.tbItems);<br />
this.Controls.Add(this.panel1);<br />
this.Name = "MainForm";<br />
this.Text = "MainForm";<br />
this.ResumeLayout(false);<br />
}<br />
#endregion<br />
void BCreateClick(object sender, System.EventArgs e)<br />
{<br />
int noOfItems = 0;<br />
try<br />
{<br />
noOfItems = Int32.Parse(tbItems.Text); <br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show("There was a problem. Creating 5 items instead.\r\n" + ex.Message);<br />
noOfItems = 5;<br />
}<br />
for (int i = 0; i < noOfItems; i++)<br />
{<br />
IndexedMenuItem itemToAdd = new IndexedMenuItem(i+1);<br />
itemToAdd.Click += new System.EventHandler(this.indexedMenuItem_Click);<br />
itemToAdd.Text = "Generated IndexedMenuItem No. " + (i + 1).ToString();<br />
contextMenu1.MenuItems.Add(itemToAdd);<br />
}<br />
MessageBox.Show("Items created");<br />
<br />
<br />
}<br />
<br />
void standardMenuItem_Click(object sender, System.EventArgs e)<br />
{<br />
MessageBox.Show("The standard MenuItem was clicked.");<br />
}<br />
void indexedMenuItem_Click(object sender, System.EventArgs e)<br />
{<br />
MessageBox.Show("A generated IndexedMenuItem was clicked. The item clicked had the identifier " + ((IndexedMenuItem)sender).Identifier.ToString());<br />
}<br />
<br />
}<br />
<br />
public class IndexedMenuItem : System.Windows.Forms.MenuItem<br />
{<br />
private int identifier;<br />
public int Identifier<br />
{<br />
get<br />
{<br />
return identifier;<br />
}<br />
}<br />
<br />
public IndexedMenuItem(int newIndex)<br />
{<br />
identifier = newIndex;<br />
}<br />
<br />
<br />
}<br />
}
Cheers
Sid
|
|
|
|
|
Im gonna do something very interesting tomorrow afternoon (I want to see if it works out). I dont want to go into any details, but that MAY be fun.
However, I am too tired. I came home late and tried to chop up a few lines to solve your problem.
That did not work out the way I thought it would. I did not reread your - or my - post, and simply assumed this was what you wanted. I read your startpost and my first reply and understood that I did not post what you or I wanted..
Shame on me. I need to get some sleep now, so try if you can use any of this code and come back tomorrow at the same time, I might have posted something useful by then.
Cheers
Sid
|
|
|
|
|
G'day Sid,
I think you have gone beyond the call of duty. Actually, you probably wont like to hear this but I came up with a novel solution myself. The night I had replied to your solution which i had found difficult to understand. Well the next morning I took another look at your difficult solution and an idea spawned which helped me overcome my problem. I couldnt believe it was so simple, so it looks like C# is slowly sinking into me .
I skimmed through your second solution and will go through it line by line once I get some sleep tonight.
Once again a million thanks for helping me out here. I truly appreciate it.
many thanks
Veeral
|
|
|
|
|
I have a problem in coding the code to compile and execute.I want to do an IDE eg. something like JCreator in Java that executes code and compiles it but its been giving me huge problems.Can you please help me!!
uni1985
|
|
|
|
|
First of all this forum handles C# problems, and second but not least : where is your problem??
I hope you understand...
By the way... visit http://nehe.gamedev.net[^]
|
|
|
|
|
This really isnt too difficult (if its all about a one-codefile project, that is):
Simply run some shell with "csc.exe codefile.cs" and pipe the output to a richTextBox or similar. then check if the new "codefile.exe" exists and spawn a shell with "codefile.exe".
That should do the job.
I just don't know how to create a shell under .NET
Cheers
Sid
|
|
|
|
|
Hi,
Guess this article will help you.
http://www.codeproject.com/csharp/matheval.asp
Thanks
SGS
|
|
|
|
|
hi..hi..hi
i want to aske you if you has information about (system class)in c#
and its used and how i can use it to do somthing like
shutdown and serial port.....
thank thank thke
ooosoooory the (thke) i mean thank............
|
|
|
|
|
I dont know a class in the FCL named System , but sure there is a namespace called System , if there is a class named system till us in which namespace this class exists , and lets discover together what this class can do ...
|
|
|
|
|
Hi, I think that he was mean system namespase because there is not systen class in .NET
|
|
|
|
|
Hello
I have a very difficult problem to explain. I have a password dialog box so that people can change there password. The dialog box will request for their current password, anc check that is is valid. Then request them to enter their new password and then re-enter their new password. The passwords are checked using the tab button when they leave a text box on the (leave event). When they have done all this they click the ok button and the new password is set. If however, they cancel using the cancel button. Then the dialog box will not close. This is the code below so you can better understand my problem.
This is the code for when the user enters the password, and presses the tab key to go to the next text box. When this event fires it will check the password is correct. Enter new password and re-enter password uses the same idea. I will not post it here as the code is the same.
<br />
private void txtEnterPassword_Leave(object sender, System.EventArgs e)<br />
{<br />
string queryValidatePwd = "SELECT Username, Password FROM AdminUsers WHERE Username = '" + lblLoginName.Text + "' AND Password = '" + txtEnterPassword.Text + "' ";<br />
<br />
try<br />
{<br />
OleDbCommand cmdValidatePwd = cnnChangePassword.CreateCommand();<br />
cmdValidatePwd.CommandType = CommandType.Text;<br />
cmdValidatePwd.CommandText = queryValidatePwd;<br />
<br />
OleDbDataAdapter daValidatePwd = new OleDbDataAdapter(cmdValidatePwd);<br />
DataTable dtValidatePwd = new DataTable("AdminUsers");<br />
<br />
int count = daValidatePwd.Fill(dtValidatePwd);<br />
if ( daValidatePwd.Fill(dtValidatePwd) == 1 )
{<br />
txtEnterNewPassword.Visible = true;<br />
txtEnterNewPassword.Focus();
}<br />
else<br />
{<br />
MessageBox.Show("Password is incorrect for this username - please try again","Incorrect Password",MessageBoxButtons.OK,MessageBoxIcon.Warning);<br />
txtEnterPassword.Clear();<br />
txtEnterPassword.Focus();<br />
}<br />
dtValidatePwd.Dispose();<br />
daValidatePwd.Dispose(); <br />
}<br />
catch ( OleDbException ex )<br />
{<br />
MessageBox.Show(ex.Message);<br />
}<br />
catch ( Exception ex )<br />
{<br />
MessageBox.Show(ex.Message);<br />
}<br />
}<br />
Code for when the user closes the dialog box. The the other textboxes have focus you cannot close this form. I have tired using this.close() as well, but still does not work.
<br />
private void btnCancel_Click(object sender, System.EventArgs e)<br />
{<br />
this.Dispose();<br />
}<br />
Thanks for you help in advance,
Steve
|
|
|
|
|
Your code looks fine to me, perhaps you should use the Close procedure to close your window. You say that the windows doesn't close so as odd as this may sound, but you should check all the events you handle, maby one of them is stopping you from closing your form.
I hope you understand...
By the way... visit http://nehe.gamedev.net[^]
|
|
|
|
|
In Click event handler for your Cancel Button , if you showed the form with ShowDialog (a modal dialog), try:
DialogResult = DialogResult.Cancel That should work.
Otherwise, call Hide if you created a modeless dialog (Form.Show ).
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Did you try setting the CancelButton property on the form to your Cancel button?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
HI,
how to use win32 datatype in c#.NET
am using
[DllImport("Kernel32", CharSet=CharSet.Auto)]
private unsafe static extern UInt32 CreateIoCompletionPort(UInt32 hFile, UInt32 hExistingCompletionPort, UInt32* puiCompletionKey, UInt32 uiNumberOfConcurrentThreads);
this function , n i wants to pass a socket to ist parameter as a handle
and when i convert socket to UInt32 it gives me
INVALID CAST EXCEPTION
so how i pass socket to UInt32 hFile this argument.???
please help me ...........
Thanks
babur.saeed@gmail.com
its_me_babar@yahoo.com
Babar
|
|
|
|
|
Handle dataTypes in C# must be IntPtr, therefor you procedure should look like this :
[DllImport("Kernel32")]
private static extern IntPtr CreateIoCompletionPort(IntPtr hFile, IntPtr hExistingCompletionPort, IntPtr puiCompletionKey, IntPtr uiNumberOfConcurrentThreads);
I hope you understand...
By the way... visit http://nehe.gamedev.net[^]
|
|
|
|
|
Thank u very much i have solved the problem,,,,,,,,
but now stuck into another problem
can u help me if i send u code?
|
|
|
|
|
|
Hi,
when i create a software with c# for different OS, do i need to compile the source code on every computers with destination OS, i mean, i create a project on winxp, but i wont that is runnable on windows2000 to, do i must to compile the project on win2000 first befor a create a release? I hope that my question is understandable!
thanx
mirsad
|
|
|
|
|
Hi!
No, you don't have to compile for every OS.
There are, however, some classes in the .NET framework that are not supported on every OS .NET runs on (for example, a FileSystemWatcher only is available on NT-based systems: NT, 2000, XP, 2003).
The framework documentation tells you which OS's a class is supported on.
mav
|
|
|
|
|