int IMAGE_WIDTH = SelectedCameraInThr.CaptureAreaInfo.Size.Width;
int IMAGE_HEIGHT = SelectedCameraInThr.CaptureAreaInfo.Size.Height;
int stride = IMAGE_WIDTH;
Bitmap b24bpp = new Bitmap(IMAGE_WIDTH, IMAGE_HEIGHT, PixelFormat.Format24bppRgb);
var rect = new Rectangle(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT);
var bitmapBytes = new byte;
var bmp = new Bitmap(pictureBox.Width, pictureBox.Height, PixelFormat.Format24bppRgb);
var graph = Graphics.FromImage(bmp);
float scale = (float)Math.Min(1.0 * pictureBox.Width / IMAGE_WIDTH, 1.0 * pictureBox.Height / IMAGE_HEIGHT);
var scaleWidth = (int)(IMAGE_WIDTH * scale);
var scaleHeight = (int)(IMAGE_HEIGHT * scale);
Rectangle PicRect = new Rectangle((pictureBox.Width - scaleWidth) / 2, (pictureBox.Height - scaleHeight) / 2, scaleWidth, scaleHeight);
while (bCapture )
{
exp = CamCtrl.Value/1000;
exp = exp > 200 ? 200 : exp;
if (SelectedCameraInThr.GetVideoData(dataPtr, bufferSize, exp))
{
Marshal.Copy(dataPtr, buffer, 0, bufferSize);
var bitmapData = b24bpp.LockBits(rect, ImageLockMode.WriteOnly, b24bpp.PixelFormat);
var numberOfBytes = bitmapData.Stride * IMAGE_HEIGHT;
var ptr = bitmapData.Scan0;
if(SelectedCameraInThr.CaptureAreaInfo.ImageType == ASICameraDll.ASI_IMG_TYPE.ASI_IMG_RAW8
|| SelectedCameraInThr.CaptureAreaInfo.ImageType == ASICameraDll.ASI_IMG_TYPE.ASI_IMG_Y8)
{
int j = 0;
foreach (byte i in buffer)
{
bitmapBytes = i;
bitmapBytes = i;
bitmapBytes = i;
}
Marshal.Copy(bitmapBytes, 0, ptr, bitmapBytes.Length);
}
else if (SelectedCameraInThr.CaptureAreaInfo.ImageType == ASICameraDll.ASI_IMG_TYPE.ASI_IMG_RGB24)
{
Marshal.Copy(buffer, 0, ptr, bitmapBytes.Length);
}
else
{
int i, j = 0, iLen = buffer.GetLength(0);
byte Temp8;
for (i = 1; i < iLen; i += 2)
{
Temp8 = buffer;
bitmapBytes = Temp8;
bitmapBytes = Temp8;
bitmapBytes = Temp8;
}
Marshal.Copy(bitmapBytes, 0, ptr, bitmapBytes.Length);
}
b24bpp.UnlockBits(bitmapData);
graph.DrawImage(b24bpp, PicRect);
pictureBox.Image = bmp;
}
}