日期:2014-05-17  浏览次数:20689 次

C# 如何把Picturebox图片付给bitmap
我定义了一个bitmap,想把picturebox4的图像付给它,然后在上面作图,再赋给pictureBox1.可是出了问题:

private Bitmap pic1; 
pic1 = pictureBox4.Image;//这一句出错了
//错误9无法将类型“System.Drawing.Image”隐式转换为“System.Drawing.Bitmap”。存在一个显式转换(是否缺少强制转换?)
Graphics g1 = Graphics.FromImage(pic1);
Pen mypen = new Pen(Color.Red);
g1.DrawLine(mypen, tempx_pre, tempy_pre,tempx,tempy); 
g1.Dispose();
pictureBox1.Image = pic1;
c# pictureBox bitmap 转换

------解决方案--------------------
pic1 = (Bitmap)pictureBox4.Image;
------解决方案--------------------
Bitmap bmp = pictureBox1.Image as Bitmap;