图片框图像的边框 [英] Border for the picture box image

查看:115
本文介绍了图片框图像的边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码在Windows Mobile中显示图像的边框.但是,边框不会显示所有图像,任何人都可以建议

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

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);



预先感谢,
Varshini M.



Thanks in advance,
Varshini M.

推荐答案

代码对我来说似乎是正确的,但是请不要忘记释放资源(使用using关键字或Dispose方法).因此,您可能正面临内存问题.例如:

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();
}


这篇关于图片框图像的边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆