简体   繁体   English

如何在Picturebox中定义的区域内显示图像?

[英]How do I display an image within a region defined in a Picturebox?

As a follow on to my previous question I have gotten my region but spent the last two hours trying to display tiny pictures wihing that region alone; 作为对上一个问题的补充,我进入了我的区域,但在过去的两个小时中,我尝试仅显示该区域的小图片。 with the end goal being to be able to arbitarily display any number of images I choose. 最终目标是能够任意显示我选择的任意数量的图像。 so far this is my code: 到目前为止,这是我的代码:

    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

I have tried the DrawImageUnscaled method also but I either get a my tiny picture blown to fill the pie region or nothing is displayed. 我也尝试了DrawImageUnscaled方法,但是我要么吹了一张很小的图片来填充饼图区域,要么什么都不显示。

This line: 这行:

pb.Image = (blip);

is what's causing the tiny image to appear large. 是导致微小图像显得较大的原因。 Basically, you pulling a tiny bitmap out of resources, and then setting the PictureBox's Image property to that bitmap (I'm assuming "pb" is a PictureBox on your form). 基本上,您从资源中提取了一个很小的位图,然后将PictureBox的Image属性设置为该位图(我假设“ pb”是窗体上的PictureBox)。 Try commenting out that line and the line below it. 尝试注释掉该行及其下方的行。

Click here to run a sample application that demonstrates the basics of how to do radar (or one way, at least). 单击此处以运行示例应用程序,该示例应用程序演示了如何进行雷达操作(至少是一种方法)的基础。 Note: this application does not do double-buffering or transparency of the tiny image. 注意:此应用程序不对小图像进行双缓冲或透明处理。

Source code for the project is here . 该项目的源代码在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM