putting border around image


M

Mike P

I am reading an image from a database and writing it to the screen. But
now I also need to put a border around this image. Here is my code :

public void showSelectedImage(string strEncodedImage)
{
Response.Clear();
Response.ContentType = "image/jpeg";

System.Drawing.Image image = retrieveImage(strEncodedImage);

System.Drawing.Image.GetThumbnailImageAbort dummyCallback;

dummyCallback = new
System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);

System.Drawing.Image thumb;

thumb = image.GetThumbnailImage(1200, 800, dummyCallback,
IntPtr.Zero);

thumb.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg);
}

public bool ThumbnailCallback()
{
return false;
}

private System.Drawing.Image retrieveImage(string strEncodedImage)
{
System.Drawing.Image image = null;

byte[] imageData = Convert.FromBase64String(strEncodedImage);

MemoryStream memStream = new MemoryStream(imageData);
image = System.Drawing.Image.FromStream(memStream);

return image;
}

Is it possible to add a border to this image?
 
Ad

Advertisements

A

Alberto Poblacion

Mike P said:
I am reading an image from a database and writing it to the screen. But
now I also need to put a border around this image. Here is my code :

public void showSelectedImage(string strEncodedImage)
{
Response.Clear();
Response.ContentType = "image/jpeg";

System.Drawing.Image image = retrieveImage(strEncodedImage);

System.Drawing.Image.GetThumbnailImageAbort dummyCallback;

dummyCallback = new
System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);

System.Drawing.Image thumb;

thumb = image.GetThumbnailImage(1200, 800, dummyCallback,
IntPtr.Zero);

thumb.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg);
}

public bool ThumbnailCallback()
{
return false;
}

private System.Drawing.Image retrieveImage(string strEncodedImage)
{
System.Drawing.Image image = null;

byte[] imageData = Convert.FromBase64String(strEncodedImage);

MemoryStream memStream = new MemoryStream(imageData);
image = System.Drawing.Image.FromStream(memStream);

return image;
}

Is it possible to add a border to this image?

In order to add the border, you would need to create a Bitmap which is
slightly larger than the image, use Graphics.DrawImage to draw the image at
the center of the bitmap, and use Grahics.DrawRectangle (for instance) to
draw the border on the bitmap. You would then save that bitmap into the
response stream in the same way as you are currently returning "thumb".

However, there is another easier way. I imagine that you are using this
code to return an image that you are then displaying inside a web page by
means of an <img> whose "src" points to the page or handler that contains
your sample code. If that is the case, then the simplest way of adding a
border is to add a style="border..." attribute to your <img> tags.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top