J
Joe Cool
I am attempting to add a function to an application I am working on to
modify the JPEG Comment in a Jpeg image file.
I can retrieve the JPEG Comment with no problem. The problem is
modifying it.
I have the contents of a Jpeg loaded into an Image object, _Image,
using the Image.FromFile method.
I convert the Text property of a TextBox to a byte array with code
like this:
Byte[] byteArr = new Byte[txtDescription.Text.Length + 1];
for (int i = 0; i < txtDescription.Text.Length; ++i)
byteArr =
Convert.ToByte(Convert.ToChar(txtDescription.Text.Substring(i, 1)));
byteArr[txtDescription.Text.Length] =
Convert.ToByte(Convert.ToChar("\0"));
I load the current JPEG Comment with:
PropertyItem prop;
prop = _Image.GetPropertyItem(0x9286);
I modify that with:
prop.Len = byteArr.GetUpperBound(0) + 1;
prop.Value = byteArr;
I set the Jpeg Comment in the Image in memory with:
_Image.SetPropertyItem(prop);
I then save the image to a new file with:
FileStream myWriter;
myWriter = new FileStream("c:\\temp.JPG", FileMode.Create,
FileAccess.Write);
_Image.Save(myWriter, ImageFormat.Jpeg);
myWriter.Close();
myWriter.Dispose();
Sometimes it works. But everytime I try to modify the value I was able
to change it to to something else, it always reverts to the original
value, "LEAD Technologies, Inc. V1.0".
I have dumped the byte array, byteArr, to the debug window and it
always appears to be exactly what I am expecting it to be.
Any ideas?
modify the JPEG Comment in a Jpeg image file.
I can retrieve the JPEG Comment with no problem. The problem is
modifying it.
I have the contents of a Jpeg loaded into an Image object, _Image,
using the Image.FromFile method.
I convert the Text property of a TextBox to a byte array with code
like this:
Byte[] byteArr = new Byte[txtDescription.Text.Length + 1];
for (int i = 0; i < txtDescription.Text.Length; ++i)
byteArr =
Convert.ToByte(Convert.ToChar(txtDescription.Text.Substring(i, 1)));
byteArr[txtDescription.Text.Length] =
Convert.ToByte(Convert.ToChar("\0"));
I load the current JPEG Comment with:
PropertyItem prop;
prop = _Image.GetPropertyItem(0x9286);
I modify that with:
prop.Len = byteArr.GetUpperBound(0) + 1;
prop.Value = byteArr;
I set the Jpeg Comment in the Image in memory with:
_Image.SetPropertyItem(prop);
I then save the image to a new file with:
FileStream myWriter;
myWriter = new FileStream("c:\\temp.JPG", FileMode.Create,
FileAccess.Write);
_Image.Save(myWriter, ImageFormat.Jpeg);
myWriter.Close();
myWriter.Dispose();
Sometimes it works. But everytime I try to modify the value I was able
to change it to to something else, it always reverts to the original
value, "LEAD Technologies, Inc. V1.0".
I have dumped the byte array, byteArr, to the debug window and it
always appears to be exactly what I am expecting it to be.
Any ideas?