我正在尝试检索在Panel上绘制的图像。从SDK中为指纹扫描仪绘制图像。这是我用来尝试从面板中获取扫描指纹的代码。
int width = Convert.ToInt32(pnlRightThumb.Width);
int height = Convert.ToInt32(pnlRightThumb.Height);
Bitmap left_thumb = new Bitmap(width1, height);
pnlLeftThumb.DrawToBitmap(left_thumb, new Rectangle(0, 0, width1, height1));
left_thumb.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Fingerprints", "left.bmp"), ImageFormat.Bmp);
到目前为止,我所能获得的只是一张白色图片。
注意:我无法改变图像的绘制方式,我只能尝试从面板中获取绘制的图像。
答案 0 :(得分:1)
关键是绘制图像的方式。如果你无法控制它,我就必须使用Graphics对象对你的面板进行快照。尝试这样的事情:
int width = Convert.ToInt32(pnlRightThumb.Width);
int height = Convert.ToInt32(pnlRightThumb.Height);
Bitmap left_thumb = new Bitmap(width1, height);
Graphics g = Graphics.FromImage(left_thumb);
Point panel_location;
panel_location=pnlRightThumb.PointToScreen(Point.Empty);
g.CopyFromScreen(panel_location.X, panel_location.Y, 0, 0, left_thumb.Size, CopyPixelOperation.SourceCopy);
left_thumb.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Fingerprints", "left.bmp"), ImageFormat.Bmp);