[英]How do I display an image within a region defined in a 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)。 尝试注释掉该行及其下方的行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.