[英]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.