Click here to Skip to main content
15,912,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I used the code below to display the border for an image in Windows Mobile. But, border is not displaying for all the images, can anyone suggest

C#
hReq = (HttpWebRequest)WebRequest.Create("xxxx.com/" + ImgUrl);
hRes = (HttpWebResponse)(hReq).GetResponse();
Stream str = hRes.GetResponseStream();
picRestLogo.Image = new Bitmap(str);
Graphics g = Graphics.FromImage(picRestLogo.Image);
Pen p = new Pen(Color.FromArgb(146, 146, 146));
Rectangle panelRect = picRestLogo.ClientRectangle;
g.DrawLine(p, panelRect.Left, panelRect.Top, panelRect.Right - 1, panelRect.Top);
g.DrawLine(p, panelRect.Left, panelRect.Top, panelRect.Left, panelRect.Bottom - 1);
g.DrawLine(p, panelRect.Right - 1, panelRect.Top, panelRect.Right - 1, panelRect.Bottom - 1);
g.DrawLine(p, panelRect.Left, panelRect.Bottom - 1, panelRect.Right - 1, panelRect.Bottom - 1);


Thanks in advance,
Varshini M.
Posted
Updated 14-Feb-11 0:57am
v2
Comments
Manfred Rudolf Bihy 14-Feb-11 6:57am    
Edit: Added pre code tags.

1 solution

The code seems correct to me but don't forget to release the resources (use the using keyword or Dispose method). You're maybe facing a memory problem because of that. For example:

//the Graphics object will be disposed automatically with using
using (Graphics g = Graphics.FromImage(picRestLogo.Image))
{
   Pen p = new Pen(Color.FromArgb(146, 146, 146));
   Rectangle panelRect = picRestLogo.ClientRectangle;
   g.DrawLine(p, panelRect.Left, panelRect.Top, panelRect.Right - 1, panelRect.Top);
   g.DrawLine(p, panelRect.Left, panelRect.Top, panelRect.Left, panelRect.Bottom - 1);
   g.DrawLine(p, panelRect.Right - 1, panelRect.Top, panelRect.Right - 1, panelRect.Bottom - 1);
   g.DrawLine(p, panelRect.Left, panelRect.Bottom - 1, panelRect.Right - 1, panelRect.Bottom - 1);
   //release the pen
   p.Dispose();
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900