چطور میشه یک فلدر که حاوی تعدادی عکس رو بگیریم و عکس های اون فلدر با استفاده ار picture viewer ویندوز و یا هر برنامه یا component دیگه قابلیت های picture viewer رو داشته باشه رو نمایش بدیم؟
ممنون میشم کمکم کنید.
Printable View
چطور میشه یک فلدر که حاوی تعدادی عکس رو بگیریم و عکس های اون فلدر با استفاده ار picture viewer ویندوز و یا هر برنامه یا component دیگه قابلیت های picture viewer رو داشته باشه رو نمایش بدیم؟
ممنون میشم کمکم کنید.
خوب مشکلی مگه داری تو این؟ تنها ترفند اون خوندن فایل ها از فولدره.
با استفاده از system.io.directories.getdirectories بکنی که قبلا بحث شده و بعد
image image =new image.fromfile(path ) و بعد دیگه حل شده
شما وقتی فایلها رو از یک فولدر میخونید یعنی آدرس و نام فیل ها رو دارین. پس فقط میمونه که بگین با چه برنامه ای باز کنید. واسه همین هم با توابع رشته ای سه حرف آخر رو جدا کنید و بزارین تو یه Case و هر type رو با برنامه دلخواهتون باز کنید.
معمولا اکثر برنامه ها از طریق خط فرمان، پارامتر ورودی میگیرند. یکی از این پارامترها همیشه نام فایل است.
مثلا اگه شما دستور زیر رو در خط فرمان اجرا کنید صرفنظر از اینکه ویندوز شما فایلهای JPG رو بصورت پیشفرض با چی باز میکنه، عکس مربوطه با MSPaint باز میشه :
mspaint C:\WINDOWS\Web\Wallpaper\Ascent.jpg
و چنانچه دستور رو به شکل زیر بنویسید، همون تصویر در Windows picture and fax viewer باز میشه:
C:\Windows\system32\rundll32.exe C:\Windows\system32\shimgvw.dll,ImageView_Fullscre en C:\WINDOWS\Web\Wallpaper\Ascent.jpg
اینم کد سی شارپ برای دوستانی که نمیدونن چطور باید مطالب پست قبلی رو کد کنن :
private void Form1_Load(object sender, EventArgs e)
{
ShowPicture(@"C:\Windows\Web\Wallpaper\Ascent.jpg" );
ShowPicture(@"C:\Windows\Greenstone.bmp");
}
private static void ShowPicture(string filename)
{
System.IO.FileInfo file = new System.IO.FileInfo(filename);
if (file.Extension.ToLower() == ".jpg")
{
//Open with the 'Windows picture and fax viewer':
System.Diagnostics.Process.Start(@"C:\Windows\syst em32\rundll32.exe ", @"C:\Windows\system32\shimgvw.dll,ImageView_Fullsc reen " + filename);
}
else
{
//Open with the 'Microsoft Paint':
System.Diagnostics.Process.Start(@"C:\Windows\syst em32\MSPaint.exe ", filename);
}
}