|
it's not that difficult. If it's generic array, and you don't have any specific information about array (specific information would be e.g. "it's sorted array"), you have to go through whole array - that's common sense. You can optimize this stupid algorithm only if you know something more... As already suggested, you could keep a variable with maximal/minimal value. Or you can have sorted array. Or if you need better performance (e.g. it's BIG array - I can think of sizes 1000+ ) you may consider different structure than array - heap, tree etc. Or you can sort array once and then find min and max is easy and in O(1). It really depends on what is in array and how you use the array... without more information, answer is you can't do anything better then O(N) (meaning: check all N items in array).
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
Hi,
Let me tell you whole information.I had taken generic array not sorted one and it's single dimentional array.I am storing the pixel value of the image(i.e. R,G,B) into that single dimentional array.I want to find out the Minimum and maximum value from the pixel.so now i think u got whole idea.
so now for getting excellent performance what is the best way?
I think now u r having whole information.
|
|
|
|
|
Since you are adding each value to the array yourself just check each value against a Min and Max variable before you enter it into the array. i.e.
if(CurrentValue < MinValue)
MinValue=CurrentValue;
else if(CurrentValue > MaxValue)
MaxValue=CurrentValue;
Array.Add(CurrentValue);
|
|
|
|
|
Hi,
yeh i had applied logic which you had suggested but here as i am first using math.min(,) method which for looping the color pixel ,it only gives me min. value of last two pixels ,not min. value of whole pixels.
here is the code,
for (int row = rect.Left; row < rect.Right; row++)
{
for (int col = rect.Top; col < rect.Bottom; col++)
{
// XmlElement nodeColorFG = xmlDoc.CreateElement("COLOR");
dropColors[k] = PixelInfo.getColor(row, col);
if (dropColors[k].R < MinRvalue)
{
Minmax.MinRvalue = dropColors[k].R;
}
else if (dropColors[k].R > MaxRvalue)
{
Minmax.MaxRvalue = dropColors[k].R;
}
//RAvg+= dropColors[k].R / TotalPixels;
//Getting the Minimum & Maximum value of the Red (R) colors.
if (k!=0)
{
MinRvalue = Math.Min(dropColors[k-1].R, dropColors[k].R);
MaxRvalue = Math.Max(dropColors[k - 1].R, dropColors[k].R);
}
//Getting the Minimum & Maximum value of the Green (G) colors.
//GAvg += dropColors[k].G / TotalPixels;
BAvg += dropColors[k].B / TotalPixels;
k++;
//if (dropColors[k - 1].R > dropColors[k].R) Minmax.MinRvalue = dropColors[k].R;
}
}
so can you suggest me some more changes to get min. and maxi. value of whole pixels?pls.
|
|
|
|
|
Ok, I'm not sure what your variable Minmax is, but here is a possible solution to your problem...
for (int row = rect.Left; row < rect.Right; row++)
{
for (int col = rect.Top; col < rect.Bottom; col++)
{
dropColors[k] = PixelInfo.getColor(row, col);
Minmax.MinRvalue = Math.Min(Minmax.MinRvalue,dropColors[k].R);
Minmax.MaxRvalue = Math.Max(Minmax.MaxRvalue,dropColors[k].R);
Minmax.MinGvalue = Math.Min(Minmax.MinGvalue,dropColors[k].G);
Minmax.MaxGvalue = Math.Max(Minmax.MaxGvalue,dropColors[k].G);
Minmax.MinBvalue = Math.Min(Minmax.MinBvalue,dropColors[k].B);
Minmax.MaxBvalue = Math.Max(Minmax.MaxBvalue,dropColors[k].B);
BAvg += dropColors[k].B / TotalPixels;
k++;
}
}
if (k!=0)
{
MinRvalue = Minmax.MinRvalue;
MaxRvalue = Minmax.MaxRvalue;
}
|
|
|
|
|
Hi,
yeh this works great but one contstrain is as below:
yours given logic is perfactly ok but now need some more logic which remove below constraints:
main problem of this logic is that as it's taking minimum and maximum value of R,G,B if user select the color in which there is one white color pixel of my logic taken white color value in min. value and so it removes all the colors from the image instead of selected color.
so i need to make some more improvement of this logic?can any one help out or guide me in changing this logic ?
thanks again
|
|
|
|
|
So add in another variable to handle White pixels. We cannot write this software for you.....
|
|
|
|
|
Hi,
Can you pls. tell me yours whole idea for improve that logic.It may possible that it helps me lot.
thanks in advance
|
|
|
|
|
I don't see how "loop inspection" on an array is a giantic performance hit but if you do not want to do that then you must create your own ArrayList (or suitable substitute).
When you override Add and Insert just put in extra logic to track the min/max. Extra work will have to be done with Remove where you probably need to search the entire array when the min/max is removed from the collection.
|
|
|
|
|
I start a thread in my program, wich do some actions. At the end of the actions it have to display (make Visible to true) a button to close the window. It seams when the thread stops (finishes) the buttons that is unvisible (Visible is false)
How can i prevent that the buttons will be only visible in the thread i started?
Thanks.
|
|
|
|
|
Hi:
i have hosted my server dll in IIS its code is like
Server view:
//server dll name is mydll.dll
<code>
namespace NameSpaceabc
{
Class ServiceProvider:MarshalByRefObject, IServices
{
void DoIt(string strWorkOnit)
{
//..do some work
}
}
}
//shared assembly has interface def
public interface IServices
{
bool DoIt(string strName);
}
the web.config file is as folllows
//////////////////////////////////////
<configuration>
<system.runtime.remoting>
<application>
<service>
<activated mode="SingleCall" type="NameSpaceabc.ServiceProvider,mydll" objectUri="services.soap" />
</service>
<channels>
<channel ref="http">
<serverProviders>
<formatter ref="soap" typeFilterLevel="Full" />
</serverProviders>
</channel>
</application>
</system.runtime.remoting>
</configuration>
//////////////////////////////////////
Client view:
HttpChannel channel = new HttpChannel();
ChannelServices.RegisterChannel(channel);
IServices iservice = (IServices )Activator.GetObject(
typeof(IServices ),"http://10.0.0.108/mydll/services.soap");
string abc="eiwero";
//as soonas i call my first method it gives an exception ..service not found
//whats the issue
iservice .DoIt(abc);
dlls are copied in the www/mydll/bin folder
web.config is in www/mydll folder
Please help
Regards
Muhammad Ahmed
Ahmed
|
|
|
|
|
Hi Ahmed,
Seems there is nothing wrong with your code. Are you getting the WSDL file when you give the URL http://10.0.0.108/mydll/services.soap?wsdl.
Thanks and Regards
Kodandapani.
|
|
|
|
|
ok,..i have fixed it by changing the server config file tag from
<activated mode="SingleCall" type="NameSpaceabc.ServiceProvider,mydll" objectUri="services.soap" />
to
<wellknown mode="SingleCall" type="NameSpaceabc.ServiceProvider,mydll" objectUri="services.soap" />
now its working fine,..
now i have another problem,.i cant debug the server side dll hosted in IIS,.although i am attaching it to w3wp.exe but to no use,.. ihave also used Debug.Assert(false) but futile,..i check the w3wp.exe using a tool the monitors path where a dll is loaded from ,..it loaded my server dll from a very starnge path,...
my dll is also not registered in GAC,..but yet it loads from that strange path,(i guess cache).i deleted my dll from that path but it copies it again,..
any help on as to how to debug,.??? as an alternative i am debugging by making a service that loads my dll,..
but how to debug using IIS????
thanks
Ahmed
|
|
|
|
|
i am trying to use following COnnection String by putting mDB file in EXE folder
String ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=myfile.mdb;Persist Security Info=False";
its throwing Exception 'file c:\myfile.mdb' was not found
I have put both EXE and MDB file in same folder..
MyBlogs
http://weblogs.com.pk/kadnan
|
|
|
|
|
I guess I'm not sure what your question is. You can fix this problem by including the full path to the MDB in the connection string. Or are you just making the comment that the OLEDB driver is not a relative path ? If you want to make sure the path to the MDB is the same as the EXE you can use the static property of Application.StartupPath...i.e.
string MDBPath=Path.Combine(Application.StartupPath,"MyFile.mdb");
String ConnStr=string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Persist Security Info=False",MDBPath);
|
|
|
|
|
You just got bit by your assumption that the current directory will be the directory that your app was launched from. This is almost always never the case.
NEVER assume that the file you want is in the current directory. ALWAYS supply a full path specification to whatever function you need.
In your case, I'm assuming that the database you want is in the same folder as your application .EXE:
string appPath = Application.StartupPath();
string filePathToDatabase = Path.Combine( appPath, "myFile.mdb" );
string connStr = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};", filePathToDatabase);
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
heres the deal. i have an image loaded into a bitmap. i have another bitmap with two colours. its like a map, i read all the black pixels and make a region out of it. now i want to stick the first bitmap into the cutout bitmap. however i want the first bitmap to be "squished" into the second, giving like a warped effect if the map is designed correctly.
this is the link to the website showing the image and the map to use.
www.users.bigpond.net.au/livebox/index.htm[^]
its a simple concept but for the life of me i cannot think of a way to do it. i thought about getting each pixel from the original and placing it inside the map but then the bitmap might not be the same size thus i have to strecth it. that and the fact that the map can be anything and my program has to skew the bitmap regardless of its shape.
thanks for your time and help in this
stumped
goran sterjov
|
|
|
|
|
Nice idea
Basically, consider the following: Do you have a single region or can there be multiple regions? If there can be multiple regions, you need to find a way to divide your image into smaller ones. Do that as you see fit
The second part: You now have an image and a corresponding "region" in which you need to "squish" your image.
Now, this is where it comes to experimenting. You need to find some algorithm which you can use to "map" image coordinates to region coordinates. if they both are of the same shape and aspect ration, you could simply "divide" the coordinated from the image (using PointF) by the resize ration (or something like this) and then draw them into your region.
Well, you want to do other regions as well, so I suggest you imagine the following situation:
You have your image, laid out in wooden cubes (pixels). You now want to push this image into a certain shape. So, you start on the outside and push the first "pixel". Doing that affects other pixels, which also change position. as you probably will not push hard enough to compress the wood, it will give way by "jumping" up, so that pixels lay over each other.
Now, if you look from above, the "image" has been pushed into shape at the expense of dozens of "pixels" overlapping each other and obstructing view. You could compensate by mixing the colors of all overlapping "pixels", but I suggest you simply remove all obstructed "pixels".
I am quite sorry that I cannot translate the following sentence, but I simply have no idea of how to say this in English:
"Die Richtung, in die du deine "Pixel" schiebst, entspricht einer Linie von der Aussenkante dieser Region zum Mittelpunkt. Stauche anhand dieser Linien, wie oben beschrieben." <- German
Cheers
Sid
|
|
|
|
|
thanks, i see what you mean and will experiment more with these nasty pixels. only hope i hit the solution soon else i will go crazy.
thanks again
goran
|
|
|
|
|
I write a asp.net program and need to know which user is now logged in clients . for example if user "A" is logged button B must enabled And if User "B" is logged button B must disabled in my webform .
Can anyone help me ?
Regards' Amir jalaly
|
|
|
|
|
Each Page has got a User attached to it, so you might want to go writing something like in your Page_Load Eventhandler:
if(User.Identity.IsAuthenticated && User.Identity.Name == "Pete") {
Button1.Enabled = true;
}
What authentication model are you using?
I love deadlines. I like the whooshing sound they make as they fly by. [Douglas Adams]
|
|
|
|
|
I am new to C# and Visual Studio.
I have created a basic application which has resulted in a .exe executable. I want to send this so that it can be reviewed by other people. The people reviewing it will not have Visual Studio and propably not even the .net framework.
How do I distribute this so that they have all the libraries and framework to allow them to run this. I will be wanting to release this in a regular bais so I don't want it to be too formal. I also want it to be very simple as it will be sent to non technical people.
Just to let you know that there is no web based content in this project - in case that makes any difference. It is all Windows Forms running on a local machine.
Thanks,
Liam
|
|
|
|
|
You can try creating a Installer project using Visual Studio. That'll result in a nice setup file that will also install the .NET framework if it is not available.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Creating an Installer is alright, but will it not mean a huge size distributable file because the Installer (bootstrapper) will add about 1MB to 2MB size, whereas .NET framework installation facility may add another about 15MB to 20MB (as the .NET framework size is that much)?
So, a small assembly of say 30 KB will become a distributable file of several MB.
But, the question is will there really be so much addition to the size?
|
|
|
|
|
hi all,
I know that How to register a event..
suppose that ,I want to register Load Event..Then we can do it like this:
this.Load += new System.EventHandler(this.Report_sessions_Load);
But How Do I unregister a Event using C#?
Thanks in advance..
|
|
|
|