I use:
propItem.Value = System.Text.Encoding.UTF8.GetBytes(textBox1.Text + "\0");
where textBox1.Text contains "MMM", to set the Value and save it in a file (propItem.Value is byte[]), but when I try to read the file I use:
string myString = System.Text.Encoding.UTF8.GetString(propItem.Value);
and get: "M\0M\0M\0\0\0". Could anybody advice how to get the proper string, without '\0'. I have seen all the answers here regarding the similar problems, but none of the answers worked in my case.
Loading the file:
Image img0 = null;
string sourceFile;
private void btnLoad_Click(object sender, EventArgs e)
{
using (var selectFileDialog = new OpenFileDialog())
{
if (selectFileDialog.ShowDialog() == DialogResult.OK)
{
sourceFile = selectFileDialog.FileName;
img0 = Image.FromFile(sourceFile);
PropertyItem[] propItems = img0.PropertyItems;
textBox1.Text = "Nothing in the file.";
foreach (PropertyItem propItem in propItems)
{
if (propItem.Id == 0x9286)
{
string myString = System.Text.Encoding.UTF8.GetString(propItem.Value);
textBox1.Text = myString ;
}
}
}
}
}