简体   繁体   中英

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.

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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