显示另一幅图像背后的图像部分

Reveal portions of an image behind another image

我有一个显示图像的 PictureBox(我们称它为 Image1)。当用户将鼠标悬停在 Image1 上时,需要显示第二张图像 (Image2)。我只需要显示 Image2 的一部分(一个 10X10 像素大小的框),而不是随着鼠标移动显示整个图像。

两张图片都是 BMP。

我怎样才能完成这个任务?我会考虑使用叠加层?

我在图片框中显示Image1,然后在内存中加载Image2,现在我只需要在鼠标移动时显示Image2在Image1上的部分。

谢谢,

这是一个例子:

public Form1()
{
    InitializeComponent();
    pictureBox1.Image = Bitmap.FromFile(your1stImage);
    bmp = (Bitmap)Bitmap.FromFile(your2ndImage);
    pb2.Parent = pictureBox1;
    pb2.Size = new Size(10,10);
    /* this is for fun only: It restricts the overlay to a circle: 
    GraphicsPath gp = new GraphicsPath();
    gp.AddEllipse(pb2.ClientRectangle);
    pb2.Region = new Region(gp);
    */

}

Bitmap bmp;
PictureBox pb2 = new PictureBox();

private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
    Rectangle rDest= pb2.ClientRectangle;
    Point tLocation =   new Point(e.Location.X - rDest.Width - 5, 
                                  e.Location.Y - rDest.Height - 5);
    Rectangle rSrc= new Rectangle(tLocation, pb2.ClientSize);

    using (Graphics G = pb2.CreateGraphics() )
    {
        G.DrawImage(bmp, rDest, rSrc, GraphicsUnit.Pixel);
    }
    pb2.Location = tLocation;
}

它使用过度偏移光标的左上角,添加一点以平滑移动..