前面概要
- 首先有几个问题
- 因为项目需要,和一个控制台程序做链接,控制台那边会输出用户选择的图片路径。
- 但是我发现如果图片路径是中文,就会乱码,报错
- 结果只需要把编码全部设置成
utf-8
就可以了 - 注意Console 输出为utf-8
Console.OutputEncoding = Encoding.UTF8;
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.InitialDirectory = "c:\\";
openFileDialog.Filter = "图片文件(*.jpg;*.jpeg;*.png)|*.jpg;*.jpeg;*.png";
openFileDialog.FilterIndex = 1;
openFileDialog.RestoreDirectory = true;
openFileDialog.Multiselect = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
var resutl = string.Join("|", openFileDialog.FileNames);
Console.WriteLine(resutl);
}
}
string filePathv = Application.dataPath + "/Other/SelectImage.exe";
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = filePathv,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
StandardOutputEncoding = System.Text.Encoding.UTF8,
};