从面板保存图像

Saving Image from 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);

到目前为止,我只能得到一张白色图像。

注意:我无法改变图像的绘制方式,只能尝试从面板中获取绘制的图像。

关键是图像的绘制方式。如果您无法控制它,我认为您必须使用 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);