他の人にも同様の問題があったことは知っていますが、私の問題は画像に固有のものです...以下のような画像関数があります:
static public string Setimage(PictureBox pictureBox, OpenFileDialog ofd,string nameform,string folderform)
{
ofd.Title = "Select Pictures";
ofd.Filter = "Pictures(*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png | All file (*.*)| *.*";
ofd.DefaultExt = ".jpg"; // Default file extension
string namefile = "";
// Process open file dialog box results
if (ofd.ShowDialog() == DialogResult.OK)
{
// try
//{
string fileName = ofd.FileName;
if (ofd.SafeFileName.Length <= 50)
if (Image.FromFile(fileName).Width >= 640 && Image.FromFile(fileName).Height >= 480)
{
namefile = ofd.SafeFileName;
if (namefile != "Null_0_Null" || namefile != null)
{
string oldPath = @ofd.FileName;
string newFileName = namefile;
newpath = Application.StartupPath + @"\userpictures\" + @"Apartment\";
deladdress = newpath + folderform + @"\" + @newFileName;
Random rand = new Random();
string pp=newpath+folderform;
// string pdest;
#region Check Directory And File To copy
if (Directory.Exists(newpath + folderform))
{
if (!File.Exists(newpath + folderform + @"\" + @newFileName))
File.Copy(oldPath, newpath + folderform + @"\" + @newFileName);
// else
// {
// File.Delete(newpath + folderform + @"\" + @newFileName);
// File.Copy(oldPath, newpath + folderform + @"\" + @newFileName);
//}
}
else
{
Directory.CreateDirectory(newpath + folderform);
File.Copy(oldPath, newpath + folderform + @"\" + @newFileName);
}
#endregion
pictureBox.BackgroundImage = Image.FromFile(newpath + folderform + @"\" + @newFileName);
}
else { MessageBox.Show("filename" + namefile + "Not valid"); }
}
else { MessageBox.Show("Size of file not valid"); }
else { MessageBox.Show("size of name file not valid"); }
// }
// catch { MessageBox.Show("your file that you selected is not valid please select anyone."); }
}
return namefile;
}
画像をロードするために、私はこの機能を持っています:
static public void loadimage(PictureBox pictureBox, string img, string nameform, string folderform)
{
try
{
if (img != "Null_0_Null")
if (!System.IO.File.Exists(Application.StartupPath + @"\userpictures\" + nameform + @"\" + folderform + @"\" + img))
{
pictureBox.BackgroundImage = Image.FromFile(Application.StartupPath + "\\filepictures\\default4.PNG");
}
else
{
pictureBox.BackgroundImage =Image.FromFile(Application.StartupPath + @"\userpictures\" + nameform + @"\" + folderform + @"\" + img);
}
}
catch { }
}
私のフォームでは、この関数を呼び出します。セット画像の場合、フォームにプライベート文字列を書き込みます。
string img1;
そして、フォームロードで画像をロードするには、次のように記述します。
loadimage(pictureBox1, "Blue hills.jpg","me", "Apartment");
img1 = "Blue hills.jpg";
私はSetimage
これを持っています:
img1=Setimage(pictureBox1, openFileDialog1,"me", "Apartment");
そして、このコードを使用して画像を削除すると、「プロセスにアクセスできません...」というエラーが表示されます
System.IO.File.Delete("image path");