|
Thanks again for getting back to me on this subject.
Luc Pattyn wrote: I don't see it!
sorry, I simply meant my discussion about having pixels stored in a double[,] array but not really caring with what pixel-depth the bitmap is since is it is only for display purposes not calculation.
5. I guess "see above"
6. Same here. Other than GDI+ not fully supporting 16bpp. There is very little on the net regarding using 16bpp greyscale Bitmaps and what there is is old and contradictory.
7. I went with your suggestion here however I couldn't get things to work using PixelFormat.Format16bppGrayScale. Instead I went with 24bppRGB instead. For the benefit of others see code below.
8. yes, I was aware of this (once) but could you remind me of the benefits? My reasons for using 2D are:
8.1 - the dimensions are carried with the data in array.GetLength(int dimension). The vector approach requires lacks this.
8.2 - the array is analogous to the raster image and therefore conceptually simpler.
8.3 - this is my first 'real' stab at writing an heavy image processing application.
Aren't the 2D and 1D arrays arranged the same in memory?
Thanks again for your help. Pushed me towards a solution.
and finally here's what I came up with:
int width = 1000;
int height = 1000;
byte[] pixelVector = new byte[width * height * 3];
for (int loop = 0; loop < (width * height ); loop+=3)
{
pixelVector[loop] = (byte)((loop * 256) / (width * height ));
pixelVector[loop + 1] = (byte)((loop * 256) / (width * height ));
pixelVector[loop + 2] = (byte)((loop * 256) / (width * height ));
}
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bmp.PixelFormat);
unsafe
{
byte* row = (byte*)bmpData.Scan0;
for (int loop = 0; loop < (pixelVector.Length*3); loop+=3){
row[loop] = pixelVector[loop/3];
row[loop + 1] = pixelVector[loop/3 ];
row[loop + 2] = pixelVector[loop/3 ];
}
}
bmp.UnlockBits(bmpData);
pictureBox1.Image = bmp;
modified 26-Jan-12 12:41pm.
|
|
|
|
|
Hi again,
5. Now I see it.
6. Yes, sthe formats aren't documented well, and the RGB approach is justified.
7. The suggestion actually was and is to fill an array with RGB bytes, then use the constructor rather than your loops, should go faster. Drawback is you have to keep the array alive, or make another copy of the bitmap.
8. Having only one pointer or one index ("loop") typically is simpler and faster than having two indexes.
9. your code as shown wouldn't work, why are you storing bytes thrice, the last two bytes will throw an IndexOutOfBoundsException; storing everything thrice isn't useful if you have an explicit copy loop anyway, it only makes sense when using the IntPtr-based constructor.
10. I'd like to know what performance you are getting when it works, I recall you used to have 200msec (for 1000*1000?).
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Hi Luc,
You spotted the mistake! Was just making sure you were paying attention. There was a factor of 3 missing from my display-array [width*height*3] and the increment on the loop is 3 not 1 (loop+=3 not loop++).
I'm filling the pixels thrice to have RGB values each the same. This gives me a greyscale and also some flexibility in that I can drop values from one of the channels and achieve colour a colour overlay effect with the same image.
With the code above using a 1000x1000 array input array ( i.e. a (1000x1000)x3 display array) I get 19ms total runtime for creating the display array, making the pixel assignments and displaying in a picture box! Nice.
Cheers for your help.
|
|
|
|
|
hello,
i need a help, can we replace the controls dynamically(example: replace radio button by textbox when some event has occurred), if yes then please help me in this
thank you
theanil
|
|
|
|
|
As you haven't specified what technology you are using (e.g. WinForms), I'm going to have to be fairly general here.
Yes you can. You would need to remove the controls you don't want from the parents control collection (you have to iterate over this using a for loop as you are removing items which you can't do inside a foreach if it directly affects the item being iterated). NOTE: Don't forget to dereference the eventhandlers.
Once you have removed them, add in your new controls taking care to set any relevant properties such as location, etc.
|
|
|
|
|
thank you,
but i tried that way,
i need to toggle between the controls and as the answer you said, deleting the controls every time and adding new one is time consuming, is there any alternate way to do this.
theanil
|
|
|
|
|
Rather than delete them, change their Visibility. The downside is that you will consume more memory leaving that much open.
|
|
|
|
|
i can try that thing, i am working on IEEE paper so i have to check for both time and memory.
theanil
|
|
|
|
|
Well, yes you can, but why would you ? Particurlarly in this case: it's hard for me to imagine a scenario in which a RadioButton (usually used in groups where the function desired is to select one option from many) replaces a TextBox, or, the reverse.
The second thought ... which I see Pete O'Hanlon has already explained, is to implement both controls, and "swap" them by changing their visibility.
In the case where both "alternate" controls expose the same Events (with the exact same type of EventArgs parameter), you could have, for example, a RadioButton and a TextBox use the same EventHandler for Click, although I think that, too is "dubious" practice: better, imho, they each have their own Click handler, and then call a common method if there's any code that both Click events need to use.
So, I suggest you re-consider your design here.
"Science is facts; just as houses are made of stones: so, is science made of facts. But, a pile of stones is not a house, and a collection of facts is not, necessarily, science." Henri Poincare
|
|
|
|
|
but the tables will created on runtime....
|
|
|
|
|
OK, I've read that statement and I don't really understand what you are after. Are you trying to create a database table at runtime, or are you trying to create an HTML table? What have you actually done so far?
|
|
|
|
|
Pete is right - that makes no sense.
You have to remember that we can't see your PC, or read your mind. All we have to work with is what you have told us, and so far, that is not a lot. There are so many different meanings of "Table" within computing, that we cannot tell which one you mean. The same applies for "Generate" - you need to specify clearly exactly what you are trying to achieve, and ideally how far you have got so far.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Nice requirements !
No memory stick has been harmed during establishment of this signature.
|
|
|
|
|
for (int i=1; i<10; i++) {
outp("table of "+i);
for(int j=1; j<10; j++) {
int k=j*i;
outp(" "+j+" * "+i+" = "+k);
}
outp("");
}
is runtime
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
posixtively awesome!
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
For a database table, you will need to create a DDL query to create the table, and then some Insert statements to put autogenerated number values into the table.
|
|
|
|
|
My son needed to create a table of some numbers for some homework this week, so I wrote a small WinForms app to do it. Here's a snippet:
private void DisplayTable()
{
int rows = (int) this.numericUpDown1.Value ;
System.Text.StringBuilder html = new System.Text.StringBuilder() ;
html.AppendFormat ("<html><head><title>{0}</title></head><body><table cols='{1}' width='100%' border='1'><tr><th>Row</th>" ,
this.textBox2.Text , this.columns.Count + 1 ) ;
for ( int c = 0 ; c < this.columns.Count ; c++ )
{
html.AppendFormat ( "<th>{0}</th>" , this.columns [ c ].Item1 ) ;
}
html.Append ( "<th>Total</th></tr>" ) ;
for ( int r = 1 ; r <= rows ; r++ )
{
html.AppendFormat ( "<tr><td>{0}</td>" , r ) ;
int tot = 0 ;
for ( int c = 0 ; c < this.columns.Count ; c++ )
{
int val = this.columns [ c ].Item2 * r ;
html.AppendFormat ( "<td>{0}</td>" , val ) ;
tot += val ;
}
html.AppendFormat ( "<td>{0}</td></tr>" , tot ) ;
}
html.Append ( "</table></body></html>" ) ;
this.webBrowser1.DocumentText = html.ToString() ;
}
P.S. I also have apps that generate DataTable s.
modified 25-Jan-12 11:06am.
|
|
|
|
|
PIEBALDconsult wrote: My son needed to create
PIEBALDconsult wrote: so I wrote
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Disturbingly for him, he only got a C-.
|
|
|
|
|
There was no requirement as to how to create the table, I assumed that using a computer program to do so was OK. As I didn't feel like teaching him Excel, I wrote a program that would allow him to create the table.
Furthermore, he had completed his ilegible hand-drawn table before I finished with the program anyway.
|
|
|
|
|
Yeah - but it was a woodwork class...
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Well, I voted this response up, simply because I like the warm feeling of thinking about a father helping his son to code.
Depending on the age of his son, and the nature of the class, and the teacher's qualifications, and what his peers may, or may not, know, about .NET, or C#: what happens when the teacher asks him to explain his solution to the class, though
best, Bill
"Science is facts; just as houses are made of stones: so, is science made of facts. But, a pile of stones is not a house, and a collection of facts is not, necessarily, science." Henri Poincare
|
|
|
|
|
It was a math class, he simply had to produce and use a table with some numbers in it to get some values to answer a few questions. The table was only an aid to answering the questions, not the answer itself. He didn't need to code, but I had hoped that he might see how having such a useful skill could benefit him.
|
|
|
|
|
I am a beginner in asp. I have a link like some thing like this http://www.mysite.com/default1.asp?id="9" . I need to change this url into like this href="http://www.mysite.com/ar/default1.asp?id="9" on a clicking a button. Means on clicking this button it will get change the url "/ar/" and the next click it will remove "/ar/" . Please some one help me to do this.
|
|
|
|
|
You might get better responses if you post this in the ASP.NET forum.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|