昨天我只是问逻辑,如果其他错误。但是当我这样做的时候?int,它的错误...
private static void mergeimagefile(string image1path, string image2path)
{
//get all the files in a directory
string jpg1 = @image1path;
string jpg2 = @image2path;
string jpg3 = @image2path;
Image img1 = Image.FromFile(jpg1);
Image img2 = Image.FromFile(jpg2);
//int width = img1.Width + img2.Width;
int width = 640;
//int height = Math.Max(img1.Height, img2.Height);
int height = 360;
int w;
if (img2.Width > 640) {
w = 640;
}
else if (img2.Width <= 640)
{
w = ((width - img2.Width) / 2);
}
System.Windows.Forms.MessageBox.Show(w.ToString());
int h = new int();
if (img2.Height > 360)
{
h = 360;
}
else if (img2.Height <= 360)
{
h = (height - img2.Height) / 2;
}
Bitmap img3 = new Bitmap(width, height);
Graphics g = Graphics.FromImage(img3);
g.Clear(Color.Black);
g.DrawImage(img1, new Point(0, 0));
//ERROR IN HERE
g.DrawImage(img2, new Point(w, h));
g.Dispose();
img1.Dispose();
img2.Dispose();
img3.Save(jpg3, System.Drawing.Imaging.ImageFormat.Jpeg);
img3.Dispose();
}
我已经尝试添加, int?
, int w = null;
, 并且根据这个 Msdn Manual,它仍然给我错误?
错误 1 使用未分配的局部变量 'w' C:\Documents and Settings\admin\My Documents\Visual Studio 2008\Projects\template\template\Form1.cs 68 50 模板
如何做到这一点?