我正在编写一个Windows窗体应用程序。我有一个从CCD相机收到的图像。相机采用12位灰度 tiff - 每像素2个字节。为了接收它我正在使用WIA(Windows图像采集)。我可以从图像数据中创建一个字节数组。之后我需要在图片框中显示图像。如果在图片框中显示,则图像太暗。此外,创建的位图是Format32bppArgb。创建位图时是否会丢失质量?如何制作所需的位图格式?我对图像处理非常陌生,任何帮助都会很棒。我已经阅读了许多关于格式之间转换主题的论坛帖子,但到目前为止还没有运气。 那么任何想法如何从我到目前为止接收16位灰度位图?
编辑:现在正在运行:
private void btnAdvancedTestSnap_Click(object sender, EventArgs e)
{
WIA.CommonDialog _dialog = new CommonDialogClass();
WIA.Device _camera = _dialog.ShowSelectDevice(WIA.WiaDeviceType.CameraDeviceType, false, false);
ImageFile imageFile = (ImageFile)_camera.Items[1].Transfer(EnvFormatID.wiaFormatTIFF);
Byte[] receivedBytes = (byte[])imageFile.FileData.get_BinaryData();
int bytecount = receivedBytes.Length;
int width = imageFile.Width;
int height = imageFile.Height;
int dimension = width * height * 2;//number of bytes representing the image - 2 bytes per pixel
int startImgBytes = bytecount - dimension;
startImgBytes += 1;// from which position of the big array to start making pixel values
byte[] imageBytes = new byte[dimension]; //byte array with only bytes,representing the picture
int j = 0;
for (int i = startImgBytes; i < receivedBytes.Length; i++)//filling the only pixel byte data array
{
imageBytes[j] = receivedBytes[i];
j++;
}
int pixDimension = width * height; //number of pixels in the image
int[] pixVal = new int[pixDimension];
int z = 0;
for (int i = 0; i < imageBytes.Length; i+=2)
{
int res = (imageBytes[i] * 0x100) + imageBytes[i + 1];//int value of the pixel, 2 bytes per pixel
int pix = (res * 255) / 4095;// scalling down to 8 bit value
pixVal[z] = pix;
z++;
}
Bitmap newImage = new Bitmap(width, height, PixelFormat.Format24bppRgb);
Color p;
//grayscale
int counter = 0;
for (int y = 0; y < height; y++)//height
{
for (int x = 0; x < width; x++)//width
{
int val = pixVal[counter];
newImage.SetPixel(x,y,Color.FromArgb(255,val,val,val));
counter++;
}
}
pbAdvanced.Image = newImage; //show the image in picture box
但这种方法对于高分辨率来说非常慢。任何想法如何提高速度。我阅读了Marshal.Copy和lockbits的示例,但在所有示例中,他们都使用源图像并复制到新的。任何帮助都将受到高度赞赏