A lost bet — Response.BinaryWrite Spoils the day!


Two days ago I lost a bet. My friend Jubair was generating a bar code image and he said how can I get it to display on the page without saving it as a file and giving its source to the image tag. I said you can’t do it because I thought it would be possible in desktop applications only. So we made a deal that if I lose I will write a blog entry for him. So here it is. Anyways, he did it in a manner similar to this one.

dim omemorystream as new memorystream()
img1.save(omemorystream,imagetype)
Response.binarywrite(omemorystream.Buffer)

Advertisements

Author: Imran Akram

A .NET/SharePoint Consultant and a political enthusiast who believes in putting the feet of the elected and/or unelected officials to fire in order to get good governance.

1 thought on “A lost bet — Response.BinaryWrite Spoils the day!”

  1. You can do better than that šŸ™‚

    Using data: URLs, you can (in the code that generates the HTML for the enclosing page) generate the image, encode it in base64, and output it as a data: URL that actually embeds the image rather than needing a separate HTTP fetch for it.

    Only recommended for small images, mind…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s