|
Its a bit difficult to help you because you do not exactly explain what you do when grayscaling and contrasting. One hint I can give you is that you should avoid the usage of the Color structure. Both the creation (e.g.Color.FromArgb) and the use of its properties (R, G, B) are relatively heavy functions (at least when using them thousand or millions of times). In one of my projects with bitmap creation and colorcalcluations I could greatly improve perfomance by not using Color. This of course means that you will need to make some implemenations by yourself (e.g. a lightweight structure for exactly your purpose).
Also have a look at NProf. With this tool you can easily find what exactly takes so long in your calculations.
|
|
|
|
|
hi,
I really like urs suggestions but is that good way to use multithreading
into R,g,b properties.
my main algorithm is that in doing grayscalling i am taking r,g,b value of each pixel & multipling with .299 for red , .587 for green and .114 for blue and then giving that new value to pixel and this algorithm takes 4 seconds becoz it's calculating thousands of pixels.
Now for doing constrasting it taking another 4 seconds.Here is algorithm.
Now in doing Constrasting,
for each R,G,B if the value is < 0 R/G/B =0 and if value >255 then R/G/B =255
so it is taking another 4 seconds.
Now can u tell me that if i will use multithreading in this both algorithm it will give me more performance or not?
I had not used multithreading ever but as concepts of multithreading is giving faclity for dividine into thread i am hoping from multithreading.
so multithreading will work or not here?
or can u tell me which good approach will help me here.
montu3377
|
|
|
|
|
On most processors multithreading wont to do much here. Processors with Hyperthreading would probably gain a bit. You should wait with this until those multicore processors arrive
Are you suing the BitmapData class to get and set the pixel values? If not you should consider doing so.
The first part of your algorithm shouldnt work with floating points. Instead I would try to use integer arithmetic (instead of r = r * 0.299 try r = r * 299 / 1000).
The second part isnt clear for me. Why should the value be < 0 ?
If you like send me (part of) your code (for me its fun doing performance tweaks) to treborg@freenet.de.
|
|
|
|
|
|
Hi,
thanks but i am using same code as he had given but here for completation of whole thing it takes 8 seconds.
So do u feels that multithreading is best approach for color dropout for making it possible in 1 second.?
|
|
|
|
|
I don't know if multithreading will be of much help here, but I've got an additional link for you: Unsafe Image Processing[^].
With just a quick look at Christian's code I think he's using a similar approach, but in the MSDN article there's an additional optimization that's reducing the time to grayscale an image from 14 seconds (pure C# without unsafe code) to ~0.5 seconds, without further voodoo like multithreading.
mav
|
|
|
|
|
Hi,
Yeah Excellent i am not having any words for saying thanks to you.You had done great job for me.After reading this article and now i am tring to implement it so most probably i will do colordropout in 1-2 seconds due to this articles.
thanks a lot to You.
|
|
|
|
|
Hi,
I really like that article for performance so from that i had implemented Grayscale in 1 second but now contrasting function is taking 4 seconds so whole color filter takes 5 seconds.
so do you have any clue or idea?how to improve that?
|
|
|
|
|
Hi!
How about adding your contrast calculation in the loop where you're grayscaling the image?
That way you don't have to iterate over all the pixels twice.
Something like this:
PixelData* pPixel = PixelAt(0, y);
for (int x = 0; x < size.X; x++)
{
byte value =
(byte) ((pPixel->red + pPixel->green + pPixel->blue) / 3);
value = (value < threshold) ? byte.MinValue : byte.MaxValue;
pPixel->red = value;
pPixel->green = value;
pPixel->blue = value;
pPixel++;
}
mav
|
|
|
|
|
Hi,
I Have A parent window in that by pressing a HOTKEY A window(navigating window) opens By Pressing the Link in the Hotkey window it navigates to another page.My Question is If I defaultly closing The Parent window(i.e main window) The hotkey window(navigating) also must Be closed
Prabhakar.A
Software Engineer
|
|
|
|
|
Hi!
Why not just call the navigation window's Close() method in the Closing event handler of your main window?
mav
|
|
|
|
|
yea it will be closed
ByMindOnlyYouCanDoIt
|
|
|
|
|
hi all,
I am using two axwebbrowsers in a form and am populating those with htms. I want to add synchronised scrolling(horizontal and vertical) to these browser controls. Can anyone help me here?
PS: i am totally new to C#, so please be generous in explanation...
Thanks in advance
Pai
|
|
|
|
|
hello;
i've recently re-did my website from the ground up in asp.net technology. im still new to it all, because im use to the old linux servers using php.
basically what im trying to do, is set up a paging system on a datalist. the data is loaded from an xml file to a dataset. i found tutorials online on how to do pagination but it all uses sql databases and the paging is different since im loading xml into a dataset.
im also writing this in c#.
here is a link to the pages im trying to paginate: http://www.jt-fx.com/debauchery/photoalbum.aspx?imgID=2005/03
any help would be appreciated
thanks,
jt
|
|
|
|
|
i forgot, here is the code-behind that loads the pictures:
private void Page_Load(object sender, System.EventArgs e) {
if(!Page.IsPostBack) {
BuildGrid();
}
}
public void BuildGrid() {
string path = null;
if (Request.QueryString["imgID"] != null) {
path = Server.MapPath("~/images/photoalbum/") + Request.QueryString["imgID"] + "/images.xml";
FileInfo fi = new FileInfo(path);
if (fi.Exists) {
XmlDocument doc = new XmlDocument();
DataSet ds = new DataSet();
ds.ReadXml(path);
dlImages.DataSource = ds;
dlImages.DataBind();
} else {
lblError.Visible = true;
}
}
}
|
|
|
|
|
Hello dear all
i m working in C# windows based application i have a one problem i have selected many row in datagrid ho can i find the selected row index number of data grid please help me......
Priyank Gupta
|
|
|
|
|
try this : datagrid.SelectedIndex
The future will not remember;
The past does not forget!
|
|
|
|
|
this is not a property of datagrid;
|
|
|
|
|
Have a look at the DataGrid.IsSelected property.
This will tell you whether a row is selected or not. You will have to loop through all rows to find those that are selected.
|
|
|
|
|
yes your are right now i have implemented by this property but in my grid there is thousands record in grid then if i will search by loop then it will take more time
do you have nay other feature for searching selected row in data grid
please help me
tahnks for reply
Priyank Gupta
|
|
|
|
|
Sorry, but as far as I know there is no other way. If you should find one then tell me
|
|
|
|
|
there is a way to find the row index number of a selected row, but as far as i know it can only return you one row index, so even if 6 rows are selected you wil only get one row index
the way to do this is:
dataGrid.CurrentCell.RowNumber;
|
|
|
|
|
Hi,
I'm trying to send an image from a C# WinForm app to a PHP page in binary format.
All PHP is taken care of, and security is of no concern.
My problem is that I'm not sure how the correct way to post the info is..
So far, I've got:
///////////Code Starts...
string myUrl=/*myURLhere*/;
string result ="";
FileStream fs = new FileStream(@"c:\image.jpg", FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
Byte[] buffer = br.ReadBytes((int)fs.Length);
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(myUrl);
wr.Method= "POST";
wr.ContentType = "application/x-www-form-urlencoded";
wr.ContentLength = buffer.Length + 8; //For the variable header "myImage=" in POST
StreamWriter sw = new StreamWriter(wr.GetRequestStream());
sw.Write("myImage=" + buffer);
sw.Close();
HttpWebResponse webResponse = (HttpWebResponse)wr.GetResponse();
Stream s = webResponse.GetResponseStream();
StreamReader sr = new StreamReader(s);
result = sr.ReadToEnd();
/////////////End Code
The debugger stops at the line
HttpWebResponse webResponse = (HttpWebResponse)wr.GetResponse();
With error:
Additional information: The request was aborted: The request was canceled.
Any suggestions?
Many thanks to anyone who can help out.
Timbo
|
|
|
|
|
hiii,
how can i get processes handles which work on file.
i mean, if a process opend a file and works with it; how can i know it's handle from the opend file.
thanx for your time.
marcoryos
|
|
|
|
|
Greetings,
Question: When one news an object (class) eg:
MyClass myClass = new MyClass();
Are only the fields (class level variables that aren't in any method) getting newly allocated memory to store them, or are all the methods (functions) getting memory allocated for them as well?
I understand that variables in the scope of methods do get allocated when the method is called then removed when the method returns but what about the code of the method... where does it live? And does it get replicated on each new?
Here is another way to ask it... If I have 1000 newed instances of MyClass in an array and inside of MyClass I have 25 methods that have a lot of code in them. Do I now have 1000 copies of those method's code in memory too?
I think what would help is if I knew where the code itself lives in memory... and, whether or not there is only one copy of it in memory even if you create multiple pointers to it with new.
Please set me straight... any help will be greatly appreciated.
EB
|
|
|
|