M
mortb
I'm writing a page that will get an image which the user wants to download.
I'm trying to find some way to set the "description" field of the file to
write some relevant information to the user.
The code I have (parts found on the internet) looks like this:
private void Page_Load(object sender, System.EventArgs e)
{
MemoryStream memStream = new MemoryStream();
string imageId = Request.QueryString["id"];
imageId = imageId != null ? imageId : "dummy.png";
Response.ContentType = "image/png";
Bitmap oImg;
try
{
oImg = new Bitmap(Server.MapPath(imageId));
}
catch
{
oImg = new Bitmap(16, 16);
}
// set the description field
PropertyItem[] items = oImg.PropertyItems;
PropertyItem propTemp = items[0];
string description = "Exported";
byte[] Value = System.Text.ASCIIEncoding.Unicode.GetBytes(description);
propTemp.Id = 0x010E; // id of "description" field
propTemp.Type = 2;
propTemp.Len = Value.Length;
propTemp.Value = Value;
oImg.SetPropertyItem(propTemp);
oImg.Save(memStream, System.Drawing.Imaging.ImageFormat.Png); // must use
memory stream as saving png format needs stream to be searchable
memStream.WriteTo(Response.OutputStream);
}
My problem is that this code does not add any data to the description field.
If I look in the outputted image in a program that displays the binary data
the field (tEXtDescription) has been inserted but my string "Exported does
not follow. What is going wrong?
cheers,
mortb
I'm trying to find some way to set the "description" field of the file to
write some relevant information to the user.
The code I have (parts found on the internet) looks like this:
private void Page_Load(object sender, System.EventArgs e)
{
MemoryStream memStream = new MemoryStream();
string imageId = Request.QueryString["id"];
imageId = imageId != null ? imageId : "dummy.png";
Response.ContentType = "image/png";
Bitmap oImg;
try
{
oImg = new Bitmap(Server.MapPath(imageId));
}
catch
{
oImg = new Bitmap(16, 16);
}
// set the description field
PropertyItem[] items = oImg.PropertyItems;
PropertyItem propTemp = items[0];
string description = "Exported";
byte[] Value = System.Text.ASCIIEncoding.Unicode.GetBytes(description);
propTemp.Id = 0x010E; // id of "description" field
propTemp.Type = 2;
propTemp.Len = Value.Length;
propTemp.Value = Value;
oImg.SetPropertyItem(propTemp);
oImg.Save(memStream, System.Drawing.Imaging.ImageFormat.Png); // must use
memory stream as saving png format needs stream to be searchable
memStream.WriteTo(Response.OutputStream);
}
My problem is that this code does not add any data to the description field.
If I look in the outputted image in a program that displays the binary data
the field (tEXtDescription) has been inserted but my string "Exported does
not follow. What is going wrong?
cheers,
mortb