private string buffer1;
private string buffer2;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openDlg = new OpenFileDialog();
openDlg.Filter = "图形文件(*.jpg)|*.gif";
openDlg.FileName = "";
openDlg.DefaultExt = ".gif";
openDlg.CheckFileExists = true;
openDlg.CheckPathExists = true; DialogResult res = openDlg.ShowDialog();
if (res == DialogResult.OK)
{
for (int i = 0; i < openDlg.FileNames.Length; i++)
{
buffer1 = openDlg.FileNames[i].ToString();
}
} EncodeWithString(); } public byte[] EncodeWithString()
{
System.IO.FileStream inFile;
byte[] binaryData;
try
{
inFile = new System.IO.FileStream(buffer1, System.IO.FileMode.Open, System.IO.FileAccess.Read);
binaryData = new Byte[inFile.Length];
long bytesRead = inFile.Read(binaryData, 0, (int)inFile.Length);
inFile.Close();
}
catch (System.Exception exp)
{
System.Console.WriteLine("{0}", exp.Message);
return null;
}
try
{
buffer2 = System.Convert.ToBase64String(binaryData, 0, binaryData.Length);
}
catch (System.ArgumentNullException)
{
System.Console.WriteLine("Binary data array is null.");
return null;
}
System.IO.StreamWriter outFile;
try
{
outFile = new System.IO.StreamWriter(buffer1, false, System.Text.Encoding.ASCII);
outFile.Write(buffer2);
outFile.Close();
}
catch (System.Exception exp)
{
System.Console.WriteLine("{0}", exp.Message);
}
return binaryData;
}
请问转换后的BASE64码 要引用的值的话 是buffer2吗?
private string buffer2;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openDlg = new OpenFileDialog();
openDlg.Filter = "图形文件(*.jpg)|*.gif";
openDlg.FileName = "";
openDlg.DefaultExt = ".gif";
openDlg.CheckFileExists = true;
openDlg.CheckPathExists = true; DialogResult res = openDlg.ShowDialog();
if (res == DialogResult.OK)
{
for (int i = 0; i < openDlg.FileNames.Length; i++)
{
buffer1 = openDlg.FileNames[i].ToString();
}
} EncodeWithString(); } public byte[] EncodeWithString()
{
System.IO.FileStream inFile;
byte[] binaryData;
try
{
inFile = new System.IO.FileStream(buffer1, System.IO.FileMode.Open, System.IO.FileAccess.Read);
binaryData = new Byte[inFile.Length];
long bytesRead = inFile.Read(binaryData, 0, (int)inFile.Length);
inFile.Close();
}
catch (System.Exception exp)
{
System.Console.WriteLine("{0}", exp.Message);
return null;
}
try
{
buffer2 = System.Convert.ToBase64String(binaryData, 0, binaryData.Length);
}
catch (System.ArgumentNullException)
{
System.Console.WriteLine("Binary data array is null.");
return null;
}
System.IO.StreamWriter outFile;
try
{
outFile = new System.IO.StreamWriter(buffer1, false, System.Text.Encoding.ASCII);
outFile.Write(buffer2);
outFile.Close();
}
catch (System.Exception exp)
{
System.Console.WriteLine("{0}", exp.Message);
}
return binaryData;
}
请问转换后的BASE64码 要引用的值的话 是buffer2吗?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货