superstar_v2/ImagePanel.cs
2025-04-09 10:43:09 +08:00

28 lines
795 B
C#

namespace DualScreenDemo
{
public class ImagePanel : Panel
{
public ImagePanel()
{
this.DoubleBuffered = true;
this.Size = new Size(1201, 496);
this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
}
public void SetBackgroundImageFromFile(string filePath, Rectangle cropArea)
{
Image image = Image.FromFile(filePath);
Bitmap bmp = new Bitmap(cropArea.Width, cropArea.Height);
using (Graphics g = Graphics.FromImage(bmp))
{
g.DrawImage(image,
new Rectangle(0, 0, bmp.Width, bmp.Height),
cropArea,
GraphicsUnit.Pixel);
}
this.BackgroundImage = bmp;
}
}
}