|
Thank you. I'm working on it.
|
|
|
|
|
Hi,
My problem is that I want to find a specific color in a certain area of the screen.
I'm using GetPixel[^] to find the color of a specific point on the screen, but it doesn't give me the ability to search an area of the screen.
What I have come up with so far is these while loops, which does the following:
1. Loop through the X values at the first "line" of the area.
2. Set X to 0. Increment Y by 1 (going to the next "line" of the area).
3. Repeat.
In the code below I'm searching in the area between 0,0 and 50,50.
int x = 0;
int y = 0;
int x2 = 50;
int y2 = 50;
while (x <= x2 && y <= y2)
{
while (x <= x2)
{
Color c = Win32.GetPixelColor(x, y);
if (c.R == 128 && c.G == 128 && c.B == 128)
{
}
x++;
}
x = 0;
y++;
} Can this be achieved in a better way?
By the way, as you can see in the comment in the code, I want to break out of the loop there if the specified color has been found, but it didn't work out with the break keyword. Don't tell me I have to use the G word.
Thanks.
Kristian Sixhoej
"You can always become better." - Tiger Woods
|
|
|
|
|
Hi,
as I can see it, the simplest solution is to use a flag, whether the value was found or not:
bool bFound = false;
while ((!bFound) && (x <= x2 && y <= y2))
{
while ((!bFound) && (x <= x2))
{
Color c = Win32.GetPixelColor(x, y);
if (c.R == 128 && c.G == 128 && c.B == 128)
{
bFound = true;
}
if(!bFound)
x++;
}
if(!bFound) {
x = 0;
y++;
}
}
Better way would be to put this while thing into method and call return when you found the Color.
Regards
Sebastian
|
|
|
|
|
Thanks
Kristian Sixhoej
"You can always become better." - Tiger Woods
|
|
|
|
|
int x1 = 0;
int y1 = 0;
int x2 = 50;
int y2 = 50;
Color colorCheck = new Color(128, 128, 128);
bool found = false;
for(int x = x1; x <= x2; x++)
{
for(int y = y1; y <= y2; y++)
{
if(Win32.GetPixelColor(x, y) == colorCheck)
{
found = true;
Console.WriteLine("Color found at {0},{1}", x, y);
break;
}
}
if(found)
break;
}
If only MySelf.Visible was more than just a getter...
|
|
|
|
|
Thank you
Kristian Sixhoej
"You can always become better." - Tiger Woods
|
|
|
|
|
I had two hundered tables in database. I want to retrive the tables with one common field.How to does this .I Want use C# and Sql .I had different Tonnage in all the tables. if i want to call 300 tonnage in that all the tables(200 tables).How to retrive it from the datatable in the database.
thank's in adv.
m.lavan
modified on Wednesday, February 11, 2009 4:31 AM
|
|
|
|
|
Probably best of in the database forum...
What database is it (SqlServer/Access etc), do you want to do this in C#, and what do you mean by one common field?
Regards,
Rob Philpott.
|
|
|
|
|
I'm building a screen with windows form. I need to have a start day and end day.
To solve this I'm using two dateTimePickers, one for the start and one for the end day.
When people change the end date before the start date, the start date will be that from the end date.
But when people change the start date to after the end date, the start date should be the end date. So the end date is like the master dtp.
Now there is a problem to implement this in windows XP. The error occurs when people select the start date and press the 'month further' button. When this happens, an event goes of (value changed) and there will be a check (start date before end date), if this is false the start date is set again (event goes of again) and a messagebox is shown.
But the strange thing is that directly after the first messagebox a next messagebox is shown (and the startdate is 1 month higher than before, this loops until eternity (or you close all the messageboxes with pushing enter).
In Windows Vista this won't occur.
I guess that the event (month-further-clicked) is remembered by the computer and therefore occur everytime.
But what is the workaround for this strange bug?
|
|
|
|
|
I want to get an image through webcam using c#.
can someone answer following questions
1.need i know the hardware of webcam?
2.what APIs are available in C# for getting images from webcam ?
3.when webcam is ON, where are the frames buffered before they are played?
Can Someone please guide me for how to access frames from webcam?
|
|
|
|
|
Hi all. I am stuck witha bit of a problem. I am using Threads to do my processing and to update my prgressbar. Below some of the code.
ThreadCode
private void btnRun_Click(object sender, EventArgs e)
{
ThreadStart excelrun = new ThreadStart(RunExcel);
Thread startprogress = new Thread(excelrun);
startprogress.Name = "Update ProgressBar";
startprogress.Start();
}
Code in the RunExcel calling the Progressbar thread.
progressBar1.Invoke(new updatebar(this.UpdateProgress));
UpdateProgress Code
private void UpdateProgress()
{
string filepath;
filepath = txtboxSelectTxtFile.Text;
int lines = File.ReadAllLines(filepath).Length;
progressBar1.Minimum = 0;
progressBar1.Maximum = lines;
progressBar1.Value = progressBar1.Value + 1;
int progrval = 0;
progrval = progressBar1.Value;
progrval = progrval + 1;
lblProgress.Text = ((progrval * 100) / Convert.ToInt32(progressBar1.Maximum)).ToString();
lblProgress.Refresh();
lblPercent2.Refresh();
lblRecordProcessed.Text = progrval.ToString();
lblProgText.Refresh();
lblRecordProcessed.Refresh();
}
As you can see from the above that eachtime the progressbar thread is called it does a read of the whole file to obtain the file size which is pretty inefficient. How can I change this to only read the file size once, store the size and use that to determine the Maximum size?
I am stuck and not sure how to get this changed to work more efficiently.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Set the progressbar's minimum and maximum once and not everytime in UpdateProgess. My suggestion would be to do it in RunExcel where you are processing the file(i guess so). In UpdateProgress keep on updating the current progressbar's value.
Edit - typo
|
|
|
|
|
Thanks AbitSmart. I'll try this and see how it goes.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
I tried this and I get the following Cross Thread Error when running the App.
"Cross-thread operation not valid: Control 'progressBar1' accessed from a thread other than the thread it was created on."
Any other Ideas??
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
You will have to use Invoke/BeginInvoke to update the progressbar value in another thread.
|
|
|
|
|
Furthermore,
Kwagga wrote: int lines = File.ReadAllLines(filepath).Length;
does not make sense. You don't need the actual content to determine file length, have a look at
the FileInfo class.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
I have previously tried the FileInfo Class but this then gave me problems in that with the FileInfo I get the file size and then Divide that by 1000 which left me with a rough number of say 237 if the file was 237000kb. The file has more lines than that in it and would abort when it reached 237 lines.
This is why I am trying to do it this way, get the number of records in the file once and pass that to the progressBar1.Maximum. Hope this makes sense?
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Yes I saw your earlier post with the 237 problem, which basically was caused by your code acting
as if each line contained 1000 characters.
Anyway, when you need file size in bytes, ask FileInfo, you don't need the content;
when you need file size in lines, loop a ReadLine and count them, you don't need to hold all the
lines at once (just to get array.Length), it is a waste of cycles and bytes, and an unnecessary
limitation to your app.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Friday, June 10, 2011 11:41 PM
|
|
|
|
|
But my problem with this is that each time the progreassbar thread is called it does a read to count the number of lines. Now, if I have a file with say 50000 lines of data then after each line processed it has to read through the file to get the number of lines. This is just very cumbersome and there has to be a better way of doing it. Like just getting the number of lines once and passing that the progressbar.maximum once?
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Kwagga wrote: But my problem with this is ...
so change it.
Kwagga wrote: Like just getting the number of lines once and passing that the progressbar.maximum once?
that's the advise given to you by ABitSmart; rather than repeating his words, why don't you implement it?
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi,
I have a R.A.D Window.I want when OnClientClose event raised my C# public void called.
I appreciate.
|
|
|
|
|
HI!! i have inserted image into access database. i actually want to store the address of that particular image in database. so that at the time of retrieval i will pass that address in the ASP.net image url in order to display the image. can someone help me to do this please. i have written the code in C#.
Thanks in advance.
|
|
|
|
|
|
Hi,
First of all i would like to say thanks for ur help.I plan to do the project on Networking side.
my project is ""Send SMS to Multiple recipients using C# language"".I dont have any idea about my project and also what are the external resources and software need to run this project and how to attach h/w with system.Could you please help me.
Thenmozhi.....
|
|
|
|
|
oviyaa wrote: I dont have any idea about my project
Too bad! It's your project, not ours. You have no clue at all, what to do? Then better stop it now!
oviyaa wrote: Could you please help me.
is a really stupid request here. Ask a question about a specific problem.
[edit] Ahh, you asked that question before. You say "i am a Final year MCA Student...". Can't believe that.[/edit]
|
|
|
|