N
N
NINFERIO2021-01-22 21:48:25
C++ / C#
NINFERIO, 2021-01-22 21:48:25

The process cannot access the xxx.png file when I delete an image. How to solve the problem?

Shorter. I open 10 pictures through open file dialog. Through foreach, the photos are individually edited and saved to a different folder. When it comes time to delete old photos, this error pops up.
Here is the code.

private void zatemnit () 
        {

            Bitmap img1; //Bitmap для открываемого изображения
           
            OpenFileDialog OpDi = new OpenFileDialog { Multiselect = true };
            //создание диалогового окна для выбора файла
            OpDi.Filter = "Файлы изображений (*.bmp, *.jpg, *.png)|*.bmp;*.jpg;*.png";
            if (OpDi.ShowDialog() == DialogResult.OK)
            {
                string[] result = OpDi.FileNames;
                int count = result.Length;
                progressBar1.Maximum = count;
                count = 0;
                string names = "";
                //zatemneniye
                foreach (String file in OpDi.FileNames)
                {
                   //секретный код затемнения image
                    
                    string fileName = "mem" + p + ".png";
                    //сохранение файла на пк
                    img1.Save(@"images//" + fileName);

                    names = null;
                    progressBar1.PerformStep();
                    MessageBox.Show(file);
                   

                }<--заканчивается форич
                

            }
            
            OpDi.Dispose();
            
           
        }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
NINFERIO, 2021-01-22
@NINFERIO

Ok, I added

string fileName = "mem" + p + ".png";
                    //сохранение файла на пк
                    img1.Save(@"images//" + fileName);

                    names = null;
                    progressBar1.PerformStep();
                    MessageBox.Show(file);
img1.Dispose(); ,<=== вот это, вроде работает

F
freeExec, 2021-01-22
@freeExec

The problem is in the secret code :) image still keeps the source file open, you can't delete it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question