c# bitmap和new bitmap(bitmap)及在System.Drawing.Image.get_RawFormat()报错“参数无效”

时间:2024-12-16 23:35:38

问题情境:

  给picturebox赋image属性,我用一下代码,出错:

Bitmap theBitmap = convertCameraData.display(rawDataArray, height, width, rawImageArray, rgbPalette_256, backgroundTemperature);
if (theBitmap == null) { return; }
form_Main.pictureBox1.Image = theBitmap;

困境辨析:

  把bitmap赋给pictureBox1.Image不正确,应转为image再进行赋值。

Bitmap theBitmap = convertCameraData.display(rawDataArray, height, width, rawImageArray, rgbPalette_256, backgroundTemperature);
if (theBitmap == null) { return; }
form_Main.pictureBox1.Image = new Bitmap(theBitmap);

注释:get_RawFormat()报错,意味着在格式转换的地方卡住了。把所有赋pictureBox的image属性重新更一遍。