哪位大神帮忙看下,运行一部分后报错:其他信息: GDI+ 中发生一般性错误。 5
privatevoidbuttonHB_Click(objectsender,EventArgse){for(inti=0;i<300;i++){DirectoryInf...
private void buttonHB_Click(object sender, EventArgs e)
{
for(int i=0;i<300;i++)
{
DirectoryInfo folder = new DirectoryInfo(@"F:\img\"+i.ToString());
FileInfo[] files = folder.GetFiles("*.jpg");
CombineImages(files, @"F:\img\" + i.ToString() + "pichc.jpg");
}
}
private void CombineImages(FileInfo[] files, string toPath)
{
string finalImage = toPath;
int l = files.Length;
Image[] imgs = new Image[l];
int finalWidth = 0;
int finalHeight = 0;
for (int i=0;i<l;i++)
{
imgs[i] = Image.FromFile(files[i].FullName);
finalWidth = imgs[i].Width > finalWidth ? imgs[i].Width : finalWidth;
finalHeight += imgs[i].Height;
}
Bitmap finalImg = new Bitmap(finalWidth, finalHeight);
Graphics g = Graphics.FromImage(finalImg);
g.Clear(SystemColors.AppWorkspace);
int width = finalWidth;
int height = finalHeight;
int nIndex = 0;
foreach (FileInfo file in files)
{
Image img = Image.FromFile(file.FullName);
if (nIndex == 0)
{
nIndex++;
width = img.Width;
height = img.Height;
g.DrawImage(img, 0, 0, img.Width, img.Height);
}
else
{
g.DrawImage(img, 0, height, img.Width, img.Height);
height += img.Height;
}
img.Dispose();
}
g.Dispose();
finalImg.Save(finalImage, System.Drawing.Imaging.ImageFormat.Tiff);
finalImg.Dispose();
} 展开
{
for(int i=0;i<300;i++)
{
DirectoryInfo folder = new DirectoryInfo(@"F:\img\"+i.ToString());
FileInfo[] files = folder.GetFiles("*.jpg");
CombineImages(files, @"F:\img\" + i.ToString() + "pichc.jpg");
}
}
private void CombineImages(FileInfo[] files, string toPath)
{
string finalImage = toPath;
int l = files.Length;
Image[] imgs = new Image[l];
int finalWidth = 0;
int finalHeight = 0;
for (int i=0;i<l;i++)
{
imgs[i] = Image.FromFile(files[i].FullName);
finalWidth = imgs[i].Width > finalWidth ? imgs[i].Width : finalWidth;
finalHeight += imgs[i].Height;
}
Bitmap finalImg = new Bitmap(finalWidth, finalHeight);
Graphics g = Graphics.FromImage(finalImg);
g.Clear(SystemColors.AppWorkspace);
int width = finalWidth;
int height = finalHeight;
int nIndex = 0;
foreach (FileInfo file in files)
{
Image img = Image.FromFile(file.FullName);
if (nIndex == 0)
{
nIndex++;
width = img.Width;
height = img.Height;
g.DrawImage(img, 0, 0, img.Width, img.Height);
}
else
{
g.DrawImage(img, 0, height, img.Width, img.Height);
height += img.Height;
}
img.Dispose();
}
g.Dispose();
finalImg.Save(finalImage, System.Drawing.Imaging.ImageFormat.Tiff);
finalImg.Dispose();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询