这段叠图代码有内存泄露吗?该怎么处理
这段叠图代码有内存泄露吗?
这段叠图代码有内存泄露吗,定时器每隔150ms调用该函数,叠图,在赋给图片框。(自认为没有)。
最重要的是想问注释掉的释放赋值的操作为什么没有呈现中叠图后的图片。
这段叠图代码有内存泄露吗,定时器每隔150ms调用该函数,叠图,在赋给图片框。(自认为没有)。
最重要的是想问注释掉的释放赋值的操作为什么没有呈现中叠图后的图片。
Image imgPhoto = Image.FromFile(fime); //从传入的路径构造底图
int phWidth = imgPhoto.Width;
int phHeight = imgPhoto.Height;
if (bmPhoto != null) bmPhoto.Dispose(); //**MJ:释放图片框的上一次的图片
bmPhoto = new Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb); //构造要叠图的图片
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
Graphics grPhoto = Graphics.FromImage(bmPhoto); //构造要叠图的图片的画布
//grPhoto.SmoothingMode = SmoothingMode.AntiAlias; //清除锯齿的呈现
grPhoto.DrawImage( //先将传入的路径构造图片画在其中
imgPhoto, // Photo Image object
new Rectangle(0, 0, phWidth, phHeight), // Rectangle structure
0, // x-coordinate of the portion of the source image to draw.
0, // y-coordinate of the portion of the source image to draw.
phWidth, // Width of the portion of the source image to draw.
phHeight, // Height of the portion of the source image to draw.
GraphicsUnit.Pixel); // Units of measure
imgPhoto.Dispose(); //**MJ:释放底图
for (int i = 0; i < index; i++) //叠图
{
if (i == 4 && horFlag == false) continue; //水平电机不在旋转不用画
if (i == 5 && d_vertical == false) continue; //垂直电机不在旋转不用画
if (File.Exists(FaImage[i].imagePath) == false)
{
//MessageBox.Show("加载图片不存在!", "未找到图片", MessageBoxButtons.OK, MessageBoxIcon.Warning);