我正在尝试使用c#
hide text file into imagevoid HideTextFileIntoImage(string TextPath, string ImagePath, string NewFilePath)
{
string[] Text = File.ReadAllLines(TextPath);
string[] Image = File.ReadAllLines(ImagePath);
File.Create(NewFilePath).Close();
string[] NewFile = new string[Text.Length + Image.Length];
for (int i = 0; i < Image.Length; i++)
{
NewFile[i] = Image[i];
}
for (int i = 0; i < Text.Length; i++)
{
NewFile[i + Image.Length] = Text[i];
}
StreamWriter sw = new StreamWriter(NewFilePath);
for (int t = 0; t < NewFile.Length; t++)
{
sw.WriteLine(NewFile[t]);
}
sw.Close();
}
但使用后我无法看到图像。怎么了?
答案 0 :(得分:1)
您正在尝试将二进制数据视为文本。
试试这个(完全未经测试):
void HideTextFileIntoImage(string TextPath, string ImagePath, string NewFilePath)
{
var textBytes = File.ReadAllBytes(TextPath);
var imageBytes = File.ReadAllBytes(ImagePath);
using (var stream = new FileStream(NewFilePath, FileMode.Create)) {
stream.Write(imageBytes, 0, imageBytes.Length);
stream.Write(textBytes, 0, textBytes.Length);
}
}