zoukankan      html  css  js  c++  java
  • 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);

     

  • 相关阅读:
    [BZOJ3172]单词
    [BZOJ2434]阿狸的打字机
    [BZOJ1195]最短母串
    [codeforces743E]Vladik and cards
    [BZOJ2553]禁忌
    [BZOJ1009]GT考试
    [BZOJ3507]通配符匹配
    [BZOJ4027]兔子与樱花
    test20190308
    Luogu P2742 模板-二维凸包
  • 原文地址:https://www.cnblogs.com/michellexiaoqi/p/10654907.html
Copyright © 2011-2022 走看看