| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 7767 人关注过本帖
标题:C#图片路径问题Directory.GetCurrentDirectory()
只看楼主 加入收藏
潇洒草
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2006-4-15
收藏
 问题点数:0 回复次数:16 
C#图片路径问题Directory.GetCurrentDirectory()
playpicture.Image = Image.FromFile(Directory.GetCurrentDirectory()+"\\images\\shu"+face+".jpg");
一到这里就提示错误,说是找不到图片```郁闷啊```我明明把图片放在了bin\debug\images里面了啊。而且图片名都是以shu开头后面是数字~~~
face是个int变量。
Directory.GetCurrentDirectory()这个函数是返回当前正在执行的目录路径吗?(bin\debug)?
搜索更多相关主题的帖子: Directory 路径 bin 名都 变量 
2006-04-15 13:31
水中游
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:149
专家分:0
注 册:2006-3-20
收藏
得分:0 

Directory.GetCurrentDirectory()可以到MSDN去查找它的功能。

你用的路径即使可以你生成的可执行文件也不好确定你的路径呀,
你要实现动态图象,最好用“工具箱”的Imagelist控件--属性有Image集合编辑器。

锻炼中学习……学习中成长……
2006-04-15 14:38
潇洒草
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2006-4-15
收藏
得分:0 
呵呵,不是的呀,图片是在一个文件夹里的,一共30张,让程序随机选一张图片显示。
2006-04-15 16:16
ytyt654
Rank: 2
等 级:新手上路
威 望:4
帖 子:195
专家分:0
注 册:2006-2-13
收藏
得分:0 
Application.StartupPath

2006-04-15 16:32
潇洒草
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2006-4-15
收藏
得分:0 
610机房的C#是精简版的吧?
呵呵,我在MSDN上查了,精简版的不支持Directory.GetCurrentDirectory()
.NET Framework 精简版平台说明: .NET Framework 精简版不支持 GetCurrentDirectory,因为运行 Windows CE .NET 的设备中不使用当前的目录功能。
2006-04-15 16:34
水中游
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:149
专家分:0
注 册:2006-3-20
收藏
得分:0 
用Imagelist控件,多好呀
还用什么文件夹呀,省事了。
然后产生随机数进行取出(显示)!!
要不你在仔细看一下msdn

锻炼中学习……学习中成长……
2006-04-15 16:37
水中游
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:149
专家分:0
注 册:2006-3-20
收藏
得分:0 
.NET Framework 类库

Directory.GetCurrentDirectory 方法 [C#]

请参见

Directory 类 | Directory 成员 | System.IO 命名空间 | 使用 I/O | 从文件读取文本 | 向文件写入文本 | Directory 成员(Visual J# 语法) | C++ 托管扩展编程

要求

平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列, .NET Framework 精简版 - Windows CE .NET, 公共语言基础结构 (CLI) 标准

.NET Framework 安全性:

语言

获取应用程序的当前工作目录。

[Visual Basic]
Public Shared Function GetCurrentDirectory() As String

[C#]
public static string GetCurrentDirectory();

[C++]
public: static String* GetCurrentDirectory();

[JScript]
public static function GetCurrentDirectory() : String;

返回值

包含当前工作目录的路径的字符串。

异常

异常类型 条件
UnauthorizedAccessException 调用方没有所要求的权限。

备注

当前目录不同于原始目录,后者是从其开始进程的目录。

有关使用此方法的示例,请参阅下面的“示例”部分。下表列出了其他典型或相关的 I/O 任务的示例。

若要执行此操作... 请参阅本主题中的示例...
创建文本文件。 向文件写入文本
写入文本文件。 向文件写入文本
读取文本文件。 从文件读取文本
查看目录中的文件。 Name
查看目录的子目录。 GetDirectories

GetDirectories

查看目录的所有子目录中的所有文件。 GetFileSystemInfos
查看目录大小。 Directory
确定文件是否存在。 Exists
确定目录是否存在。 Exists

示例

[Visual Basic, C#, C++] 下面的示例说明 GetCurrentDirectory 方法。

[Visual Basic] 
Imports System
Imports System.IO

Public Class Test
    Public Shared Sub Main()
        Try
            ' Get the current directory.
            Dim path As String = Directory.GetCurrentDirectory()
            Dim target As String = "c:\temp"
            Console.WriteLine("The current directory is {0}", path)
            If Directory.Exists(target) = False Then
                Directory.CreateDirectory(target)
            End If
            ' Change the current directory.
            Environment.CurrentDirectory = (target)
            If path.Equals(Directory.GetCurrentDirectory()) Then
                Console.WriteLine("You are in the temp directory.")
            Else
                Console.WriteLine("You are not in the temp directory.")
            End If
        Catch e As Exception
            Console.WriteLine("The process failed: {0}", e.ToString())
        End Try
    End Sub
End Class

[C#] 
using System;
using System.IO;

class Test 
{
    public static void Main() 
    {
        try 
        {
            // Get the current directory.
            string path = Directory.GetCurrentDirectory();
            string target = @"c:\temp";
            Console.WriteLine("The current directory is {0}", path);
            if (!Directory.Exists(target)) 
            {
                Directory.CreateDirectory(target);
            }

            // Change the current directory.
            Environment.CurrentDirectory = (target);
            if (path.Equals(Directory.GetCurrentDirectory())) 
            {
                Console.WriteLine("You are in the temp directory.");
            } 
            else 
            {
                Console.WriteLine("You are not in the temp directory.");
            }
        } 
        catch (Exception e) 
        {
            Console.WriteLine("The process failed: {0}", e.ToString());
        }
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::IO;

void main() {
    try {
        // Get the current directory.
        String* path = Directory::GetCurrentDirectory();
        String* target = S"c:\\temp";
        Console::WriteLine(S"The current directory is {0}", path);
        if (!Directory::Exists(target)) {
            Directory::CreateDirectory(target);
        }

        // Change the current directory.
        Environment::CurrentDirectory = target;
        if (path->Equals(Directory::GetCurrentDirectory())) {
            Console::WriteLine(S"You are in the temp directory.");
        } else {
            Console::WriteLine(S"You are not in the temp directory.");
        }
    } catch (Exception* e) {
        Console::WriteLine(S"The process failed: {0}", e);
    }
}

[JScript] 没有可用于 JScript 的示例。若要查看 Visual Basic、C# 或 C++ 示例,请单击页左上角的“语言筛选器”按钮

要求

平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列, .NET Framework 精简版 - Windows CE .NET, 公共语言基础结构 (CLI) 标准

.NET Framework 安全性:

请参见

Directory 类 | Directory 成员 | System.IO 命名空间 | 使用 I/O | 从文件读取文本 | 向文件写入文本 | Directory 成员(Visual J# 语法) | C++ 托管扩展编程


锻炼中学习……学习中成长……
2006-04-15 16:40
水中游
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:149
专家分:0
注 册:2006-3-20
收藏
得分:0 
上面不好看!!看这个!!

下面的示例说明 GetCurrentDirectory 方法。
[Visual Basic] 
Imports System
Imports System.IO

Public Class Test
    Public Shared Sub Main()
        Try
            ' Get the current directory.
            Dim path As String = Directory.GetCurrentDirectory()
            Dim target As String = "c:\temp"
            Console.WriteLine("The current directory is {0}", path)
            If Directory.Exists(target) = False Then
                Directory.CreateDirectory(target)
            End If
            ' Change the current directory.
            Environment.CurrentDirectory = (target)
            If path.Equals(Directory.GetCurrentDirectory()) Then
                Console.WriteLine("You are in the temp directory.")
            Else
                Console.WriteLine("You are not in the temp directory.")
            End If
        Catch e As Exception
            Console.WriteLine("The process failed: {0}", e.ToString())
        End Try
    End Sub
End Class

[C#] 
using System;
using System.IO;

class Test 
{
    public static void Main() 
    {
        try 
        {
            // Get the current directory.
            string path = Directory.GetCurrentDirectory();
            string target = @"c:\temp";
            Console.WriteLine("The current directory is {0}", path);
            if (!Directory.Exists(target)) 
            {
                Directory.CreateDirectory(target);
            }

            // Change the current directory.
            Environment.CurrentDirectory = (target);
            if (path.Equals(Directory.GetCurrentDirectory())) 
            {
                Console.WriteLine("You are in the temp directory.");
            } 
            else 
            {
                Console.WriteLine("You are not in the temp directory.");
            }
        } 
        catch (Exception e) 
        {
            Console.WriteLine("The process failed: {0}", e.ToString());
        }
    }
}

锻炼中学习……学习中成长……
2006-04-15 16:43
水中游
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:149
专家分:0
注 册:2006-3-20
收藏
得分:0 

4楼的朋友说的很好呀。
Application.StartupPath ---获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。
《来自msdn》你可以用一下!
下面的示例获取该属性并在文本框中显示其值。本示例假定 textBox1 已放置在窗体上。


private void PrintStartupPath() {
textBox1.Text = "The path for the executable file that " +
"started the application is: " +
Application.StartupPath;
}


锻炼中学习……学习中成长……
2006-04-15 16:49
潇洒草
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2006-4-15
收藏
得分:0 
我用Imagelist试试吧```
2006-04-16 16:07
快速回复:C#图片路径问题Directory.GetCurrentDirectory()
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013237 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved