Setting description field in a png image served from a web page

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
 
M

mortb

here is the data that the page returns, the description should be after the
code "tEXtDescription" but my string "Exported" is not there.
----------------------------------------------------------------------------
---------------------------------------------------

HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Wed, 28 Apr 2004 12:32:03 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Set-Cookie: ASP.NET_SessionId=taygyx455ovw5smyppmynq55; path=/
Cache-Control: private
Content-Type: image/png
Content-Length: 286

ëPNG

IHDR???C???gAMA?Å
tEXtDescriptionEv?"??IDATHK?òQ?ÇD??ç???EX6l??Jx?ê?òsN??ç??I?@E?
û?C?7¿½SlY?k4???
LiP??FV??ßKüd??^?Qg?M??¼?
K5«h\?ö<eÖ?'+R?TïÿG]?fliP÷?ÇF^£??xqè????q??¼Z?P?;^????
4L?ìà?±r???É?H?t?5/ä«»'p]níK½G?CK§??·?z?Ax?IEND«B`é
 
Top