Here is the method I call to draw a byte array (_BMData) of data to the bitmap. This is one line of data. The user can plot each line from TopToBottom or BottomToTop. The line is added to the bottom or top of the PlotAreaImage. This code works really well and is fairly fast, but this one problem. My project is rather large and complicated but if necessary I could gen up a smaller version if you want me to.
Scott
P.S. the for loop below isn't showing up well. the for loop goes from 0 to lines.
protected virtual void TransferDataToBitmap()
{
//Monitor.Enter(this);
Bitmap bm = (Bitmap)_NIGraph.PlotAreaImage;
Debug.WriteLine(string.Format("BitmapDisplayCtrl TransferDataToBitmap() {0} wd, {1} ht",bm.Width, bm.Height));
// Get bitmap. Use the LockBits method to lock the data in memory.
Rectangle rec = new Rectangle(0, 0, bm.Width, bm.Height);
BitmapData bmd=null;
try
{
bmd = bm.LockBits( rec, System.Drawing.Imaging.ImageLockMode.ReadWrite, bm.PixelFormat);
}
catch( Exception ex)
{
Console.WriteLine("Problem in TransferDataToBitmap()! {0}",ex.Message);
return;
}
int lines = _BMData.Count;
int from;
if( _DirectionOfDataFlow == DataFlowDirection.TopToBottom )
from = lines;
else
from = bm.Height-lines;
// Put the data in the bitmap
for( int i=0;
// Get a pointer to the bitmap data
int ip = bmd.Scan0.ToInt32() + (from*bmd.Stride);
// Get the Lofar data for the current line num
byte [] bData = (byte[])_BMData[i];
// Copy that data to the linenum of the bitmap
try
{
Marshal.Copy(bData, 0, (IntPtr)ip, bmd.Width);
}
catch(ArgumentOutOfRangeException ex)
{
Console.WriteLine("Problem in TransferDataToBitmap(): Marshal.Copy - Source Array Len: {0},Amount to Copy: {1} - Error: {2}", bData.Length, bmd.Width, ex.Message);
}
if( _DirectionOfDataFlow == DataFlowDirection.TopToBottom )
from--;
else
from++;
}
// Unlock it
bm.UnlockBits(bmd);
//Monitor.Exit(this);
}
Message Edited by scottyoo on 04-06-2005 07:16 PM
Message Edited by scottyoo on 04-06-2005 07:16 PM
Message Edited by scottyoo on 04-06-2005 07:22 PM
Message Edited by scottyoo on 04-06-2005 07:22 PM