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

浪子不回头ぞ 提交于 2019-12-11 16:15:32

问题


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.


回答1:


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.




回答2:


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). Try commenting out that line and the line below it.



来源:https://stackoverflow.com/questions/1319649/how-do-i-display-an-image-within-a-region-defined-in-a-picturebox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!