bitmap to two dimensional array

  • Thread starter Thread starter Btb4198
  • Start date Start date
B

Btb4198

Guest
So I have one connection to a camera but I am pulling data at multiple locations in the code. By data I mean the current frame.

My plan is to display the 8 scale version on a (Aforge) videoSourcePlayer, so the user can zoom in and out and draw a box around the area they want, but then map that to a two dimensional array of 12 byte data.

I am having a problem with the mapping, somehow when I draw the box on the videoSourcePlayer the corresponding pixels location are not the same in the two dimensional array and I am not sure why.

Furthermore, when I do a zoom in, the x and y values became negative numbers and I do not know how to map that back to my two dimensional array.

now this code works for I do everything as a bitmap:

private Bitmap Andrew()
{
Bitmap tempBitmap = new Bitmap(videoSourcePlayer.Width, videoSourcePlayer.Height);
Graphics.FromImage(tempBitmap);
Graphics g = Graphics.FromImage(tempBitmap);
Bitmap originalBmp = videoSourcePlayer.GetCurrentVideoFrame();
while (originalBmp == null)
{
originalBmp = videoSourcePlayer.GetCurrentVideoFrame();
}
g.DrawImage(originalBmp, videoSourcePlayer.imagex, videoSourcePlayer.imagey, videoSourcePlayer.imgWidth, videoSourcePlayer.imgHeight);

return tempBitmap;
}


but when I try to do the two dimensional array my locations are off.

and again I do not know how to handle the negative numbers when it comes to zoom in and out .

here is my code :


public double[,] GetSnapshot()
{
global_x = 0;
global_y = 0;
int rawImageSize = DetermineRawImageSize();
byte[] temp = new byte[rawImageSize];

float[] parameters = new float[1];
parameters[0] = 1.5F;
transfer.bits = new byte[getBufferSize()];
FrameDescriptor frameDesc = new FrameDescriptor();
//gets frame from camera
ReturnCode rc = Api.GetNextFrame(m_hCamera, transfer.bits.Length, transfer.bits, ref frameDesc);
int i4 = 0;
int value2 = 0;
global_y = (int)(videoSourcePlayer.imgHeight - videoSourcePlayer.imagey);
global_x = (int)(videoSourcePlayer.imgWidth - videoSourcePlayer.imagex);
double[,] returndata = new double[global_x, global_y];

for (int x = (int)videoSourcePlayer.imagex; x < global_x; x++)
{
for (int y = (int)videoSourcePlayer.imagey; y < global_y; y++ )
{
int value = ((transfer.bits[i4] << 8) + transfer.bits[i4 + 1]);
value2 = (value >> 4);
returndata[x,y]= value2;
i4 = i4 + 2;
}
}
return returndata;
}


can someone help me

Continue reading...
 
Back
Top