|
If I understand correctly, you have at most a 1024*1024 color image, that is scrolling horizontally and gets up to 25 columns added per second, with a producer you control. That should not be any problem.
Yes, I think I have used ScrollWindows in the dark ages of Win32, I wouldn't need it in .NET
I would consider a Control (say a Panel) that would show a Bitmap and accept a columnar data update. Give me 24 hours, I'll experiment a bit in C#, and get back to you.
What would you want for initial content? axes? grid lines? legend?
BTW: I found a plotting graph here: High Speed, Feature Rich, and Easy-To-Use Graphs and Charts[^]. Haven't looked inside yet.
|
|
|
|
|
Hi Luc,
Sounds cool! looking forward to see what you come up with.
For the spectrogram I wouldn't worry about axis for my app but if you want to write an article you might want to put a frequency and time axis and possible a colorbar which maps the spectrogram colors to an intensity for the frequency components.
Let me know if I can contribute in any way...going to bed know
Thx
Tom
|
|
|
|
|
Hi Tom,
1.
I studied the article High Speed, Feature Rich, and Easy-To-Use Graphs and Charts[^] a bit; it has a Plotter class which is a UserControl displaying a number of traces, each trace defined as a sequence of points. So there is no bitmap, no image, involved at all. It basically is vector graphics, which makes it high-performance.
2.
I did some experiments with a bitmap-based plotter-like Panel, where one column of pixels would be updated at a time, using the circular buffer approach we discussed earlier. It is double-buffered to avoid flickering, and it works remarkably smooth, in fact it looks much better than the other article's demo, however I suspect that is due to the demo having fewer data points than the plotter is wide, causing the graph to jump all the time.
At 512*512 my plotter happily handles 30 updates (frames) per second, using between 10 and 15% of a middle-of-the-road dual-core (I use both cores, as one executes the main thread, i.e. the painting, whereas the other calculates the new column in a BackgroundWorker).
Yet I am convinced it takes too much CPU load for the net result. So I think I should look into other technologies, being OpenGL and DirectX. And I will, in time.
3.
For the moment, I'm convinced if all that gets shown basically is a line graph, one should not resort to images at all. It will be much more lightweight when the graphs are drawn straight from a sequence of points, no matter what technology is used for painting images.
ADDED
Of course, when doing so, there is no problem whatsoever to make it scroll.
/ADDED
|
|
|
|
|
Hi Luc
Glad to hear you are in good progress. I will take a look at the article you are refering to.
I've advanced a bit tonight myself because the spectrogram is now up running. I'm currently using drawImage() which seems to do well. My laptop (Lenovo T61p) uses about 20% of it's resources but the app also does FFTs 50 times a second and computes the log-spectrum of these FFT outputs which costs a little too so I'm pretty impressed with the GDI performance.
Even though I running double-buffering I still think my 768x1024 pixel spectrogram does some flickering..do you have a way to get rid of this?
Also, I need an efficient way of mapping from FFT log-outputs to a colorrange...you know of an easy way of doing this?
Sorry for all the question...I have a lot to learn with .NET (and programming in general besides Matlab)
Addition: I guess the flickering comes because I'm manipulating the bitmap directly and not bitmapdata. If that is the case maybe drawimage is not such a good option????
Thx
Thomas
modified on Tuesday, September 21, 2010 12:09 AM
|
|
|
|
|
bimbambumbum wrote: .do you have a way to get rid of this?
yes. do it correctly.
and no. there is no perfect solution, switching from one image to the next always takes a finite amount of time, it is a matter of getting it minimal. you will not see flickering when the repaint time is small compared to the steady time.
I suggest you show the relevant code.
bimbambumbum wrote: mapping from FFT log-outputs to a colorrange
technically, have an array of colors, one for each integer in a limited range of possible values (if need be, divide by some constant so only say 256 colors remain).
esthetically, whatever you like. You could create a hue-wig, i.e. all colors with same (probably max) saturation and brightness but different hue values.
|
|
|
|
|
Hi Luc
Here is the core of my bitmap shifting. If you run it you can see that the shifting flickers a little and I would like to avoid that.
Hope you have a simple way of getting rid of the flickering. Sorry for the messy code....Mind you I'm a newbie
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using fftwlib;
namespace GDI_evaluation
{
public partial class Form1 : Form
{
Timer timer = new Timer();
Graphics g;
int XREF = 50;
int YREF = 50;
Bitmap myBitmap;
Random rnd;
int tIndx = 0;
public Form1()
{
InitializeComponent();
rnd = new Random();
this.SetStyle(
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer, true);
myBitmap = new Bitmap(768, 512, PixelFormat.Format24bppRgb);
timer.Tick += new EventHandler(timer_tick);
timer.Interval = 1000 / 25;
timer.Enabled = true;
timer.Start();
}
void timer_tick(object sender, EventArgs e)
{
this.Refresh();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
}
protected override void OnPaint(PaintEventArgs pe)
{
g = pe.Graphics;
Rectangle block1 = new Rectangle(XREF + tIndx, YREF, myBitmap.Width - tIndx, myBitmap.Height);
g.DrawImage(myBitmap, block1, 0, 0, myBitmap.Width - tIndx, myBitmap.Height, GraphicsUnit.Pixel);
Rectangle block2 = new Rectangle(XREF, YREF, tIndx, myBitmap.Height);
g.DrawImage(myBitmap, block2, myBitmap.Width - tIndx, 0, tIndx, myBitmap.Height, GraphicsUnit.Pixel);
int tIndx2 = tIndx - 1;
if (tIndx2 < 0)
tIndx2 = myBitmap.Width - 1;
for (int ii = 0; ii < myBitmap.Height; ii++)
myBitmap.SetPixel(myBitmap.Width - 1 - tIndx2, ii, Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)));
if (++tIndx == myBitmap.Width)
tIndx = 0;
}
}
}
|
|
|
|
|
Hi,
I did not run your code, I have some comments just by looking at it:
1.
you paint onto your Form, I always avoid that. I prefer adding a Panel to the Form, then painting to the Panel. Make the Panel the exact size of the plot, and make the Panel double-buffered, not the entire Form.
ADDED
and only repaint (i.e. Invalidate or Refresh) the panel.
/ADDED
2.
I see you modify your data inside OnPaint; one should not do that, as OnPaint may be called by the system whenever it feels a need (e.g. when an unrelated window gets shown, then disappears, uncovering your window).
3.
you should use a local variable to store the value of myBitmap.Height, and not call any unnecessary property inside a loop; it will typically not be optimized away!
4.
bimbambumbum wrote: opdater grafik 50 /sekund!!!
?
|
|
|
|
|
Hi Luc
Thanks for your comments.
I get your points - I think
Will try to follow your recipe when I have time tomorrow.
If you have an example I can steal from that would be great...
Thanks
Thomas
|
|
|
|
|
bimbambumbum wrote: I'm manipulating the bitmap directly
so do I. The alternative with LockBits prevents multi-threading, i.e. you can no longer have concurrent image updates and image repaints by different threads.
However, SetPixel() is a very slow method. My test does two DrawLine() to update one column (one full-height background, one foreground).
|
|
|
|
|
One last thing...
Will my spectrogram shift more smoothly if I do it the panel way?
Cheers
Tom
|
|
|
|
|
My plotting Panel is perfectly smooth, however I can't compare, I never do it the Form way, as
1) it isn't really object-oriented
2) too many things probably are going on with Forms.
|
|
|
|
|
I just wonder if a (dependency)Object can be made aware of data bindings, e.g. if it acts as binding source.
It would be nice to get an event from somewhere to realize that someone bound to my object and to get the path that was used on it. So the object could see that a binding to one of it's public properties was created.
But seems like the .NET framework offers no such capabilities for data binding.
Any ideas or suggestions how to create something comparable?
Cheerio,
Don Rolando
|
|
|
|
|
Hi
I'm a newbie struggling with a picturebox.
At construction time I load a jpg image into a picturebox and I have 3 radio-buttons that dictate what what is drawn in the GUI. When the picturebox is enabled & visible at construction time then it stays visible even if I make it invisible later by pressing a radiobutton (picturebox1.visible = false) .
Can someone please tell me what I'm missing?
Regards
Tom
|
|
|
|
|
Hmm, just solved it myself...
when I replace:
BitmapCanvas.Visible = false;
With:
this.BitmapCanvas.Visible = false;
Then I can make the visible picturebox go invisible!
Wonder why that is needed?
Probably a no-brainer
Thomas
|
|
|
|
|
This problem happens when you have a parameter or variable in a method that has the same name as the field of a class, such as:
class MyClass
{
private int value;
public MyClass(int value)
{
this.value = value;
}
}
You can tell by hovering the mouse over value in the code editor.
|
|
|
|
|
bimbambumbum wrote: BitmapCanvas.Visible = false;
hover BitmapCanvas, right-click for "Go to definition" and see if that is what you expect it to be.
|
|
|
|
|
If my applications (mainly WinForms, C#) work in older versions of .NET Framework, should I publish them in older or new version? Is there any criteria that I should look for?
Thanks in advance!
|
|
|
|
|
It really depends on the kind of application and who it is intended for.
If you do not need any features of the latest version and if you do not use any libraries built with the latest version of the framework, then it might be appropriate to build your project for an older version of .NET.
For example .NET 3.0 is pre-installed on all Windows Vista computers and .NET 3.5 ships with Windows 7. Therefore if you chose .NET 3.0 as your target framework, there will be more users able to use your application out of the box.
|
|
|
|
|
Fresh-Grass wrote: If my applications (mainly WinForms, C#) work in older versions of .NET Framework, should I publish them in older or new version? Is there any criteria that I should look for?
Deploy them against the version you have tested on. Later versions may contain fixes/changes to behaviour that you rely on - the argument here is that you should really test on the latest version with Service Packs that you can.
|
|
|
|
|
I had an issue recently in 2.0 that was fixed in service pack 1. I then found that 2.0 SP1 is bundled as part of 3.5 SP1 so if I was starting a new project I would not bother with anything lower than 3.5 SP1
If you want a widest potential audience for your application, it is probably best to stick to 2.0 however, as it is part of 3.0 and 3.5, and therefore will be on more machines than any other version.
The only versions worth upgrading from, and it is an upgrade not just recompile, is from 1.0 and 1.1. Even Microsoft are not supporting them much these days.
|
|
|
|
|
|
Hi,
1.
when you are creating a managed-code project (say an EXE file mainly consisting of C# code), then the only stuff you can "Add a Reference" is more managed code; unmanaged aka native code DLLs can be used through a technology known as P/Invoke; this does not rely on any "reference", Windows will locate those native code libraries just like it always has, by looking for them in a predefined set of folders (see the PATH environment variable).
2.
P/Invoke is pretty complex. I'm working on a little article series on the subject, part 1 of it is available here.
3.
There is an alternate route, where you would build a managed C++/CLI wrapper to the native code (using another "technology" known as "it just works"). Some are strongly in favor of that route, I'm not, as I'm not very active in C++ and don't want to rely on a third language to connect the two languages I do use most (C# and C).
|
|
|
|
|
Hi Luc
Thanks for your support.
I managed to get the FFT working as I found a P/invoke FFTW project I could "borrow" from.
I appreciate that you spend time writting your reply to me.
Will take a look at your article and try get familiar with P/Invoke.
Thanks again
Tom
|
|
|
|
|
Hi All,
I got a requirement to import and export the data from different databases, flat files, csv files and xml files. I am unable to decide whether I sould use typed datasets and SSIS for the same. This is first I am getting this kind decision making responsibility.
Can anybody give me any suggestions, or links to calculate the pros and cons of both methods. Any link or advice or anything will be helpfull. In this mean time I will google the this.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
Hey geniuses, it's me again. Google has failed me so I humbly come to you with a question about how .NET performs string comparisions.
A tiny bit of background, I'm reseaching how the use of string constants is better than hardcoding string literals (beyond good coding practice).
I wrote this code to check the various ways .NET handles strings.
string s = "howdy";
if (HELLO_W == "hello")
{
Console.WriteLine("condition 3");
}
And then checked the IDL with ildasm.exe
IL_0033: ldstr "howdy"
IL_0038: stloc.1
IL_0039: ldc.i4.0
IL_003a: stloc.2
IL_003b: nop
IL_003c: ldstr "condition 3"
IL_0041: call void [mscorlib]System.Console::WriteLine(string)
IL_0046: nop
So where is the string comparision? When I compare two ints, I see the comparision command "ceq".
As always, I appreciate your insights and am not afraid to kiss a little butt to get it.
|
|
|
|
|