using (Bitmap gdiBitmap = new Bitmap(System.Configuration.ConfigurationSettings.AppSettings["imagePathren"]))
{//图片
// Thread.Sleep(5);
try
{
DeleteDC(hBitmap);
using (Bitmap bmp2 = new Bitmap(gdiBitmap.Width, gdiBitmap.Height))
{
//将第一个bmp拷贝到bmp2中
Graphics draw = Graphics.FromImage(bmp2);//这句报GDI 一般性错误
draw.DrawImage(gdiBitmap, 0, 0);
draw.Dispose();
gdiBitmap.Dispose();//释放bmp文件资源
hBitmap = bmp2.GetHbitmap();
IntBitmap = hBitmap.ToInt32();
image.Picture = utils.hBitmapToPicture(IntBitmap);
image.XllCenter = X - image.Width / 2;
image.YllCenter = Y - image.Width / 2;
if (Labellist[i].WorkerName != null && Labellist[i].WorkerName != "")
{
MapWinGIS.Labels la = new MapWinGIS.Labels();
la.AddLabel(Labellist[i].WorkerName, X, Y + 30, 0, 1);
la.FrameBackColor = (uint)ColorTranslator.ToOle(Color.Red);
la.FontColor = (uint)ColorTranslator.ToOle(Color.Red);
image.Labels = la;
la.Clear();
}
axMap.UpdateImage(hndl);
bmp2.Dispose();
}
}
catch (Exception ex)
{
}
}
Thread.Sleep(2000);
}
finally
{
DeleteDC(hBitmap);
GC.Collect();
}
}
刚开始不会出错,运行到9000多次后就开始报错了,为什么。我想知道原因,分不多求大虾解答。 这是委托实现的方法全部代码
出错位置? 运行多了才会出错好像一般都是内存溢出了~~
有什么好的解决方法不, 运行久了内存会越来越大。总是清不掉里面,没有很好的释放
DeleteDC(hBitmap);
hBitmap应该用DeleteObject删除