c# 調用聲音文件,圖片文件


聲音

一、使用C#自帶的SoundPlayer

using System.Media; 
SoundPlayer sound = new SoundPlayer("聲音.wav"); 
sound.Play();

C#中 如何將音樂文件按相對路徑存放

在資源文件中,選擇 【音頻】添加資源,把 聲音.wav添加進去。

System.Media.SoundPlayer

sound= new System.Media.SoundPlayer(Properties.Resources.聲音);
sound.Play();

 

C#中資源文件的使用

 

圖片

folderBrowserDialog控件  打開的文件夾瀏覽對話框 

 if (this.folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK),文件夾瀏覽對話框 ,如果點擊確定

  string dir = this.folderBrowserDialog1.SelectedPath;//// 取得用戶選擇的路徑

// 獲取目錄下的所有Jpg文件
string[] files = Directory.GetFiles(dir, "*.jpg", SearchOption.AllDirectories);

foreach (string imgFile in files)
{
string imageFileName; //文件名
int width, height; //寬度和高度
float dpiX, dpiY; //水平和垂直分辨率

imageFileName = Path.GetFileName(imgFile);
// 加載圖像
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(imgFile))
{
width = bmp.Width;
height = bmp.Height;
dpiX = bmp.HorizontalResolution;
dpiY = bmp.VerticalResolution;
}

string defaultPath = "";
FolderBrowserDialog dialog = new FolderBrowserDialog();
//打開的文件夾瀏覽對話框上的描述
dialog.Description = "請選擇一個文件夾";
//是否顯示對話框左下角 新建文件夾 按鈕,默認為 true
dialog.ShowNewFolderButton = false;
//首次defaultPath為空,按FolderBrowserDialog默認設置(即桌面)選擇
if (defaultPath != "")
{
	//設置此次默認目錄為上一次選中目錄
	dialog.SelectedPath = defaultPath;
}
//按下確定選擇的按鈕
if (dialog.ShowDialog() == DialogResult.OK)
{
	//記錄選中的目錄
	defaultPath = dialog.SelectedPath;
}
MessageBox.show(defaultPath);
本文固定鏈接:http://www.itechzero.com/c-sharp-folderbrowserdialog-usage.html,轉載請注明出處。
————————————————
版權聲明:本文為CSDN博主「Techzero」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/techzero/article/details/27519785

 

  // 如果目錄不存在,先創建目錄
            if (!Directory.Exists(txtDir.Text))
            {
                Directory.CreateDirectory(txtDir.Text);
            }
// 文件名
                string _filename = "file_" + (n + 1).ToString();
                // 目錄的絕對路徑
                string _dirpath = System.IO.Path.GetFullPath(txtDir.Text);
                // 組建新文件的全路徑
                string fullPath = System.IO.Path.Combine(_dirpath, _filename);

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM