Commit 1085af9b LN

打开图片报错修改

1 个父辈 43f333cc
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
this.pictureBox1.Size = new System.Drawing.Size(451, 313); this.pictureBox1.Size = new System.Drawing.Size(451, 313);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 2; this.pictureBox1.TabIndex = 2;
this.pictureBox1.TabStop = false; this.pictureBox1.TabStop = false;
// //
// txtResult // txtResult
// //
...@@ -148,7 +148,7 @@ ...@@ -148,7 +148,7 @@
// btnClearLog // btnClearLog
// //
this.btnClearLog.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnClearLog.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnClearLog.Location = new System.Drawing.Point(711, 49); this.btnClearLog.Location = new System.Drawing.Point(675, 49);
this.btnClearLog.Name = "btnClearLog"; this.btnClearLog.Name = "btnClearLog";
this.btnClearLog.Size = new System.Drawing.Size(116, 33); this.btnClearLog.Size = new System.Drawing.Size(116, 33);
this.btnClearLog.TabIndex = 12; this.btnClearLog.TabIndex = 12;
...@@ -283,7 +283,7 @@ ...@@ -283,7 +283,7 @@
this.chbUseParam.Checked = true; this.chbUseParam.Checked = true;
this.chbUseParam.CheckState = System.Windows.Forms.CheckState.Checked; this.chbUseParam.CheckState = System.Windows.Forms.CheckState.Checked;
this.chbUseParam.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.chbUseParam.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.chbUseParam.Location = new System.Drawing.Point(711, 16); this.chbUseParam.Location = new System.Drawing.Point(675, 16);
this.chbUseParam.Name = "chbUseParam"; this.chbUseParam.Name = "chbUseParam";
this.chbUseParam.Size = new System.Drawing.Size(75, 21); this.chbUseParam.Size = new System.Drawing.Size(75, 21);
this.chbUseParam.TabIndex = 26; this.chbUseParam.TabIndex = 26;
...@@ -327,7 +327,7 @@ ...@@ -327,7 +327,7 @@
this.chbZxing.Checked = true; this.chbZxing.Checked = true;
this.chbZxing.CheckState = System.Windows.Forms.CheckState.Checked; this.chbZxing.CheckState = System.Windows.Forms.CheckState.Checked;
this.chbZxing.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.chbZxing.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.chbZxing.Location = new System.Drawing.Point(792, 16); this.chbZxing.Location = new System.Drawing.Point(765, 16);
this.chbZxing.Name = "chbZxing"; this.chbZxing.Name = "chbZxing";
this.chbZxing.Size = new System.Drawing.Size(103, 21); this.chbZxing.Size = new System.Drawing.Size(103, 21);
this.chbZxing.TabIndex = 31; this.chbZxing.TabIndex = 31;
......
...@@ -146,11 +146,12 @@ namespace CodeLibrary ...@@ -146,11 +146,12 @@ namespace CodeLibrary
Image img = (Image)Image.FromFile(filename).Clone(); Image img = (Image)Image.FromFile(filename).Clone();
pictureBox1.Image = img; pictureBox1.Image = img;
Bitmap bitmap = new Bitmap(filename); Bitmap bitmap = new Bitmap(filename);
HDCodeLearnHelper.DefaultBitmap = bitmap; HDCodeLearnHelper.DefaultBitmap = bitmap;
HObject hoimg; HObject hoimg;
HDCodeHelper.Bitmap2HObjectBpp24(bitmap,out hoimg); HOperatorSet.ReadImage(out hoimg, filename);
//HDCodeHelper.Bitmap2HObjectBpp24(bitmap, out hoimg);
HDCodeLearnHelper.DefaultImage = hoimg; HDCodeLearnHelper.DefaultImage = hoimg;
ShowImage(hoimg); ShowImage(hoimg);
} }
} }
...@@ -226,6 +227,10 @@ namespace CodeLibrary ...@@ -226,6 +227,10 @@ namespace CodeLibrary
} }
public void ShowImage(HObject ho_Image) public void ShowImage(HObject ho_Image)
{ {
if (ho_Image == null)
{
return;
}
HTuple width, height; HTuple width, height;
HOperatorSet.GetImageSize(ho_Image, out width, out height); HOperatorSet.GetImageSize(ho_Image, out width, out height);
...@@ -507,61 +512,7 @@ namespace CodeLibrary ...@@ -507,61 +512,7 @@ namespace CodeLibrary
//ScanTest(); //ScanTest();
ScanDemo(100); ScanDemo(100);
}); });
} }
private void ScanTest()
{
for (int index = 1; index <= 200; index++)
{
try
{
label5.Text = "扫码测试_" + index;
int name = (index % 3) + 1;
string filename = @"F:\test\" + name + ".hobj";
if (!File.Exists(filename))
{
continue;
}
ClearPicImg();
if (filename.EndsWith(".hobj"))
{
HObject hObject = null;
HOperatorSet.GenEmptyObj(out hObject);
hObject.ReadObject(filename);
if (hObject != null)
{
HDCodeLearnHelper.DefaultImage = hObject;
ShowImage(hObject);
}
else
{
MessageBox.Show("读取文件失败:" + filename);
}
}
else
{
//读取图片内容
Image img = (Image)Image.FromFile(filename).Clone();
pictureBox1.Image = img;
Bitmap bitmap = new Bitmap(pictureBox1.Image);
HObject hoimg;
HDCodeHelper.Bitmap2HObjectBpp24(bitmap, out hoimg);
HDCodeLearnHelper.DefaultImage = hoimg;
ShowImage(hoimg);
}
btnDCode_Click(null, null);
Thread.Sleep(100);
}
catch (Exception ex)
{
HDLogUtil.error("ScanTest[" + index + "]出错:" + ex.ToString());
}
}
this.Enabled = true;
this.Cursor = Cursors.Default;
}
private void ScanDemo(int whileCount = 1) private void ScanDemo(int whileCount = 1)
{ {
...@@ -645,5 +596,6 @@ namespace CodeLibrary ...@@ -645,5 +596,6 @@ namespace CodeLibrary
string text = cmbCamera.Text; string text = cmbCamera.Text;
Clipboard.SetDataObject(text); Clipboard.SetDataObject(text);
} }
} }
} }
...@@ -258,6 +258,7 @@ namespace CodeLibrary ...@@ -258,6 +258,7 @@ namespace CodeLibrary
HDLogUtil.error("将BitMap转换为HObject对象出错:" + ex.ToString()); HDLogUtil.error("将BitMap转换为HObject对象出错:" + ex.ToString());
ho_Image = null; ho_Image = null;
} }
ho_Image = null;
return false ; return false ;
} }
public static void HObject2Bpp8(HObject image, out Bitmap res) public static void HObject2Bpp8(HObject image, out Bitmap res)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!