I tried to use this code:
----------------------------------
camera.StartExposure(14000, ASICameraDll.ASI_BOOL.ASI_FALSE);
while (camera.ExposureStatus != ASICameraDll.ASI_EXPOSURE_STATUS.ASI_EXP_SUCCESS);
int ch = 1;
int bufferSize = 0; ;
byte buffer;
PixelFormat format = PixelFormat.Format1bppIndexed;
if (camera.CaptureAreaInfo.ImageType == ASICameraDll.ASI_IMG_TYPE.ASI_IMG_RAW8 ||
camera.CaptureAreaInfo.ImageType == ASICameraDll.ASI_IMG_TYPE.ASI_IMG_Y8)
{
ch = 1;
format = PixelFormat.Format8bppIndexed;
}
else if (camera.CaptureAreaInfo.ImageType == ASICameraDll.ASI_IMG_TYPE.ASI_IMG_RAW16)
{
ch = 2;
format = PixelFormat.Format16bppGrayScale;
}
else if (camera.CaptureAreaInfo.ImageType == ASICameraDll.ASI_IMG_TYPE.ASI_IMG_RGB24)
{
ch = 3;
format = PixelFormat.Format24bppRgb;
}
bufferSize = width * height * ch;
buffer = new byte;
if (camera.ExposureStatus == ASICameraDll.ASI_EXPOSURE_STATUS.ASI_EXP_SUCCESS)
{
IntPtr dataPtr = Marshal.AllocHGlobal(bufferSize);
camera.GetExposureData(dataPtr, bufferSize);
Marshal.Copy(dataPtr, buffer, 0, bufferSize);
image = new Bitmap(width, height, format);
BitmapData bmpData = image.LockBits(new System.Drawing.Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadWrite, format);
IntPtr pNative = bmpData.Scan0;
Marshal.Copy(buffer, 0, pNative, bufferSize);
image.UnlockBits(bmpData);
var newPalette = image.Palette;
for (int index = 0; index < image.Palette.Entries.Length; ++index)
{
var entry = image.Palette.Entries;
var gray = (int)(0.30 * entry.R + 0.59 * entry.G + 0.11 * entry.B);
newPalette.Entries = Color.FromArgb(gray, gray, gray);
}
image.Palette = newPalette;
if (pictureBox1.Image != null) pictureBox1.Image.Dispose();
pictureBox1.Image = image;
Marshal.FreeHGlobal(dataPtr);
}
camera.CloseCamera();
---------------------------
but I have wrong images as a result (find in attachment)