|
Why not use a local color variable, rather than looking the color up for each iteration?
<br />
Color currColor = image.pixel[x,y].GetColor();<br />
<br />
if( ObjHash.ContainsKey(currColor) )<br />
{<br />
int val= (int)ObjHash[currColor];<br />
ObjHash[currColor]=++val;<br />
test=false;<br />
}<br />
else
{<br />
ObjHash.Add(currColor),1);<br />
list.Add(currColor);<br />
count++;<br />
}
<br />
On top of that, you could try managing your arraylist and hashtable size. As enlarging a hashtable or Arraylist is a large overhead, and you are doing 6,930,000 loops, it might be worth setting the size of your arraylist and hash table to AL.Size + 1000; when it's full. Then trim it after the loops.
Why are you swapping the arraylists at the end? This could take a while if you have a few thousand entries. Why not trim the origional one, and return that?
Cata
|
|
|
|
|
Read Christian Gauss's articles about image manipulation and start using pointers to RGB memory positions instead of pixel[x,y].
This will make your code at least 20x faster.
Perl combines all the worst aspects of C and Lisp: a billion different sublanguages in one monolithic executable. It combines the power of C with the readability of PostScript. -- Jamie Zawinski
|
|
|
|
|
Since you don't have problem with memory (you allready load a 3300x2100 image!), try allocating table that holds the colors.
int colors[]=new int[16777216];
for(int i=0;i<16777216;i++) colors[i]=0; <br />
for(int y=0;y<img.Height;y++)<br />
{ <br />
for(int x=0;x<img.Width;x++)<br />
{<br />
test = true;<br />
colors[image.pixel[x,y]]++;<br />
}
- - - - - - - - - - - - - - - - - -
Memory leaks is the price we pay \0
01234567890123456789012345678901234
|
|
|
|
|
Since we now have a tight loop, a major amount
of execution goes into checking the loop command itself.
(checking x<img.width and="" brancing="" commands)
thus,="" we="" unroll="" the="" inner="" loop!
<code="">
for(int y=0;y<img.Height;y++)
{
// do chucks of 128 pixels at once
for(int x=0;x<img.Width-128;x++)
{
// 128 times
colors[image.pixel[x,y]]++;x++;
colors[image.pixel[x,y]]++;x++;
colors[image.pixel[x,y]]++;x++;
...
colors[image.pixel[x,y]]++;x++;
colors[image.pixel[x,y]]++;x++;
colors[image.pixel[x,y]]++;x++;
colors[image.pixel[x,y]]++;
}
// do the remaining pixels
for(;x<img.Width;x++)
{
colors[image.pixel[x,y]]++;
}
}
- - - - - - - - - - - - - - - - - -
Memory leaks is the price we pay \0
01234567890123456789012345678901234
|
|
|
|
|
Hello every one:
I have a question about a Game-Source-code.I have down some soure-code from codeproject,but I can not find the "Microsoft.directx.directdraw" dll,
I can use DxVbLib onely in my code.What shoud I do?
game
|
|
|
|
|
download and install DirectX
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
That will not suffice.
You will need the DirectX SDK (download the 2003 summer update), and installed Managed DIrectX (run the dxsetup.exe with /InstallManagedDX)
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Thank you:
Where can I get the "Managed DIrectX ".
game
|
|
|
|
|
I'm rather new to oleDatabases, but I got my table setup, and connected to it in my application using the oleDbDataAdapter. I have a DataSet which gets my rows from my .mdb table, and a combobox which fills from a column in this dataset. Here are my questions:
When I fill my dataset, my combobox automatically puts the top entry of the column into the textview. I want the text to remain blank, but the container to be filled. For some reason, comboBox1.Text = ""; doesn't do the trick, even if I call it directly after filling my dataset. How do I keep the text in my comboBox from selecting the first element in the container?
After I choose an item in the container, I would like to fill other text boxes with information from the same row in my table as the item in the combo box. How do I find and retrieve the row from my dataset?
Thanks a lot for the help. I hope I wasn't too vague on anything!
|
|
|
|
|
Try selecting the index -1 to not select the first item in the list.
comboBox1.SelectedIndex = -1;
You can also use the selected index to get an offset into the dataset to get the text, but I'm sure there is a better way.
|
|
|
|
|
http://blogs.msdn.com/ericgu/archive/2004/04/01/105644.aspx
|
|
|
|
|
Good one
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
hello, all.
I am trying to convert a struct from VB to c# in order to use an old DLL. Here is the definition in VB
Public Type CHost
Host As String * 60
Port As String * 5
Info As String * 120 'Inof returned from host
Timeout As String * 10
End Type
In the sample VB code:
Public Declare Function CConnect Lib "OLDDLL.DLL" (Host As CHost) As Integer
iError = CConnect(TheHost)
and then the CHost.Info was set by the remote host.
I converted it to(C#)
public struct CHost
{
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst=60)]
public string Host; //host name
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst=5)]
public string Port; //host port
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst=120)]
public string Info; //Info returned from remote host
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst=5)]
public string Timeout; //timeout
};
in my c# code.
[DllImport("OLDDLL",EntryPoint="CConnect")]
public static extern short CConnect(ref CHost Host);
short ierror = CConnect(ref theHost);
I can connect to the remote host but the theHost.Info was not set.
Could anybody let me know what I was doing wrong and what is the right way to do it?
|
|
|
|
|
Hi,
SQLHelpder class is given in "Data Access Application Block". This block sample code is availabe on
Microsoft MSDN. Why am I using this becuase of time saving. Useful overloads are available to do more in less time.
What I need in a form is the newly added IDs in a table. For example I wrote the following code
//This module will insert a new role in the tblRole table by calling the stored procedure uspRoleNew
SqlParameter[] arparam = new SqlParameter[9];
arparam[0] = new SqlParameter("@pRoleName",SqlDbType.VarChar, 50);
arparam[0].Value= mRoleName;
arparam[1] = new SqlParameter("@pRoleDesc", SqlDbType.VarChar,50);
arparam[1].Value= mRoleDescription;
.
.
. .
arparam[8] = new SqlParameter("@pRoleIDout", SqlDbType.Int);
arparam[8].Direction=ParameterDirection.Output;
SqlHelper.ExecuteNonQuery(clsGeneral.conStr, "uspRoleNew", arparam);
int _RoleID;
_RoleID = (int)arparam[8].Value;
In paramerter[8] i want the newly added ID. But SqlHelper is not returning any value.
Below is the alternative solution for the above problem
mSqlCommand.Connection= _Sqlconn;
mSqlCommand.CommandText="uspRoleNew";
mSqlCommand.CommandType=CommandType.StoredProcedure;
mSqlCommand.Parameters.Add("@pRoleName",SqlDbType.VarChar, 50);
mSqlCommand.Parameters[0].Value=mRoleName;
mSqlCommand.Parameters.Add("@pRoleDesc", SqlDbType.VarChar,50);
mSqlCommand.Parameters[1].Value= mRoleDescription;
mSqlCommand.Parameters.Add("@pRoleIDout", SqlDbType.Int);
mSqlCommand.Parameters["@pRoleIDout"].Direction= ParameterDirection.Output;
_Sqlconn.Open();
mSqlCommand.ExecuteNonQuery();
mRoleID = (int)mSqlCommand.Parameters["@pRoleIDout"].Value;
return mRoleID;
QUESTION ????? is Why sqlhelper not doing this. If u r aware of "Data Access Application Block" plz reply.
|
|
|
|
|
Hi,
Would anybody plz screw up this code.
SqlParameter[] arparam = new SqlParameter[3];
int _GroupID;
arparam[0] = new SqlParameter("@pGroupName",SqlDbType.VarChar, 50);
arparam[0].Value= mGroupName;
arparam[1] = new SqlParameter("@pGroupDesc", SqlDbType.VarChar,50);
arparam[1].Value= mGroupDescription;
arparam[2] = new SqlParameter("@pGroupIDout", SqlDbType.Int);
arparam[2].Direction=ParameterDirection.Output;
SqlConnection _Sqlconn = new SqlConnection(clsGeneral.conStr);
SqlCommand mSqlCommand = new SqlCommand();
mSqlCommand.Connection= _Sqlconn;
mSqlCommand.CommandText="uspGroupNew";
mSqlCommand.CommandType=CommandType.StoredProcedure;
mSqlCommand.Parameters.Add(arparam);
_Sqlconn.Open();
mSqlCommand.ExecuteNonQuery();
_GroupID = (int)mSqlCommand.Parameters["@pGroupIDout"].Value;
return _GroupID;
|
|
|
|
|
How would you like us to screw it up? You can start by changing random letters in variable and class names so that it will not compile. If you'd also like some runtime errors, change the name of a couple of stored procedures.
abidkayani1 wrote:
mSqlCommand.Parameters.Add(arparam);
There is no overload of SqlCommand.Parameters.Add that accepts an array of parameters as an argument.
Charlie
if(!curlies){ return; }
|
|
|
|
|
Hi,
I have a rather simple problem, yet I can't find an acceptable solution. It isn't much of a problem for users running my application at high resolution (1280x1024 for example), but it really is for 800x600 users (too bad they still exist!)
My application is a MDI and I use FormStartPosition.WindowsDefaultBounds for each child form in order for them to open underneath the previous one (cascade).
The problem is that if I open 3 or 4 windows, a scrollbar shows up on my MDI form and the user needs to scroll to see the new windows. It happens even when no windows are open (ie: 4 windows were opened, then closed, the user will need to scroll to see the next opened window because it is not positionned at the top of the screen like it should).
Is there an easy solution to this? Anyone else having this problem?
Thanks!
Carl
|
|
|
|
|
You would have to track the position of the last form you opened. Then add whatever offsets you need in order to keep the next window inside the client area. You would be managing the position and size of the child forms yourself. Simply create a new instance of your child form, set its position and size properties, then show it.
RageInTheMachine9532
|
|
|
|
|
Isn't supposed to be done automatically for me???
|
|
|
|
|
The Default behavior doesn't take into account the size of the child window your opening... so no, it won't do it for you.
The Default behavior will walk down the parent window's client area adding up to 10 child windows stepping down and to the right until the new child window's title bar is half way down the client area of the parent window. It will then start at the top-left corner of the parent client area again and start over. It will do this without any reguard to the size of the child windows...
So if you want the entire child window inside the parent client area, you're goin got have to supply your own code for placing the child windows with reguard to it's size.
RageInTheMachine9532
|
|
|
|
|
Urg! Pain in the neck... Let's code!
|
|
|
|
|
What? You want Microsoft to do everything for you, just the way you want it?
That's why we write code! We want it done OUR way!!
RageInTheMachine9532
|
|
|
|
|
We want it our way, but we also want some free time to chill out and watch tv
|
|
|
|
|
I'm having a problem with using the Web Browser ActiveX control in a C# windows form app. The circumstance is easily reproducable:
Create the boiler plate example of this using the VS toolbox to create the ActiveX wrapper and add then drag it into your C# form.
Now, open up a web page with your forms app. For instance, mail.yahoo.com. Click in the user name entry field so that focus is there. Now minimize your form app and then bring it right back up. All of a sudden that entry field no longer has the focus.
I have another example using this control through a VC++ 6 MFC SDI app and ironically, it works fine there (the entry field still has focus).
Any ideas on what to look at? I thought it might have to do with message routing differences between windows forms and MFC SDI but hooking the app up to Spy++ didn't reveal anything. Now I'm thinking it's a problem with the .NET generated wrapper but I'm at a loss as to what to do about it.
???
any help appreciated!
|
|
|
|
|
I'm wanting to create a ToolBarMenu with a few combo boxes... I'm having problems on figuring this out.
Does anyone have any sample code to do this? (for .Net Framwork 1.1)
|
|
|
|