截取当前窗体工作区图像,保存至内存

 

//截取当前窗体图像
Bitmap bitFormImg = new Bitmap(this.Width, this.Height);
this.DrawToBitmap(bitFormImg, new Rectangle(0, 0, this.Width, this.Height));
int border = (this.Width - this.ClientSize.Width) / 2;//边框宽度
int caption = (this.Height - this.ClientSize.Height) - border;//标题栏高度

//截取签字区域图像(去边框、标题栏)
Bitmap bitSignatureImg = bitFormImg.Clone(new Rectangle(border, caption, this.ClientSize.Width, this.ClientSize.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
//创建内存流
MemoryStream Ms = new MemoryStream();
//将图像保存至内存流
bitSignatureImg.Save(Ms, ImageFormat.Bmp);
bitFormImg.Dispose();
bitSignatureImg.Dispose();

byte[] img = new byte[Ms.Length];
Ms.Position = 0;
Ms.Read(img, 0, Convert.ToInt32(Ms.Length));
Ms.Close();
string result = Convert.ToBase64String(img);

 

posted @ 2021-12-03 11:01  会跳舞的猪~  阅读(38)  评论(0编辑  收藏  举报