[英]Bitmap not loading in picturebox
我无法在PictureBox中加载位图图像。 它给我一个错误,指出参数无效。
Image up = Image.FromFile("somePath");
Image down = Image.FromFile("anotherPath");
using (down)
{
using(var bmp = new Bitmap(1000, 1000))
{
using(var canvas = Graphics.FromImage(bmp))
{
canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
canvas.DrawImage(up, 0, 0);
canvas.DrawImage(down, 0, 500);
canvas.Save();
pictureBox1.Image = bmp;// this line gives the error
}
}
}
我的pictureBox的大小也是1000X1000。 谁能告诉我我要去哪里错了?
编辑1:错误说明:
System.ArgumentException:参数无效。 在系统System.Windows.Forms.PictureBox.ImageRectangleFromSizeMode(PictureBoxSizeMode模式)在System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)在System.Windows.Forms.PictureBox.ImageRectangleFromSizeMode(PictureBoxSizeMode模式)在System.Drawing.Image.get_Size()在System.Windows.Forms.Control.WmPaint(Message&m)(位于System.Windows.Forms的System.Windows.Forms.Control.WmProint(Message&m))处的.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e,Int16层) System.Windows.Forms上的Control.ControlNativeWindow.OnMessage(Message&m)System.Windows.Forms.NativeWindow.Callback上的Control.ControlNativeWindow.WndProc(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)
删除bmp
上的using语句。 因为,您的位图被放置在pictureBox1.Image = bmp;
之后pictureBox1.Image = bmp;
并且您在绘画事件上收到错误消息。
Image up = Image.FromFile("somePath");
Image down = Image.FromFile("anotherPath");
using (down)
{
var bmp = new Bitmap(1000, 1000);
using(var canvas = Graphics.FromImage(bmp))
{
canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
canvas.DrawImage(up, 0, 0);
canvas.DrawImage(down, 0, 500);
canvas.Save();
pictureBox1.Image = bmp;// this line gives the error
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.