如何在Picturebox中定义的区域内显示图像?
问题描述:
作为我之前提到的问题,我得到了我的区域,但花了最后两个小时试图显示单独拍摄该区域的小图片;最终目标是能够任意显示我选择的任意数量的图像。 到目前为止,这是我的代码:如何在Picturebox中定义的区域内显示图像?
void OnPaintRadar(Object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Bitmap blip = new Bitmap(tst_Graphics.Properties.Resources.dogtag);
Rectangle radar_rect = new Rectangle(myRadarBox.Left + 80, myRadarBox.Left + 7, myRadarBox.Width - 200, myRadarBox.Height + 200);
using (Pen drw_pen = new Pen(Color.White, 1))
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddPie(radar_rect, 180, 180);
path.CloseFigure();
using (Region rdRegion = new Region(path))
{
g.DrawPath(drw_pen, path);
g.Clip = rdRegion;
PictureBox pb = new PictureBox();
pb.Image = (blip);
pb.Size = blip.Size;
g.DrawImage(blip, radar_rect);
}
}
}
}// end paint method
我已经试过DrawImageUnscaled方法还,但我要么得到我的小图片吹填补了馅饼区域或不显示任何内容。
答
这条线:
pb.Image = (blip);
是什么引起微小的形象出现大。基本上,你从资源拉出一个微小的位图,然后将PictureBox的Image属性设置为该位图(我假设“pb”是窗体上的一个PictureBox)。尝试评论该行及其下面的行。
+0
没有快乐。事实上,我只是认为,因为我没有使用图片框,反正评论线不会影响任何东西,因为我将图片,而不是图片框,添加到该地区。 – 2009-08-23 23:18:41
非常感谢。我会看看它,稍后再回复你。 – 2009-08-24 12:23:44