0
我尝试从一个精灵表裁剪图像并把它放在一个图片,但它不工作,任何想法,欢迎裁剪图像,并把它放在一个图片框
private void Form1_Load(object sender, EventArgs e)
{
Image Result = Crop(@"C:\Users\William\Documents\Sprites\Player\Male\Default\Light.png", 40, 60, 367, 701);
pictureBox1.Image = Result;
}
public Image Crop(string img, int width, int height, int x, int y)
{
try
{
Image image = Image.FromFile(img);
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
bmp.SetResolution(80, 60);
Graphics gfx = Graphics.FromImage(bmp);
gfx.SmoothingMode = SmoothingMode.AntiAlias;
gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
gfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
gfx.DrawImage(image, new Rectangle(0, 0, width, height), x, y, width, height, GraphicsUnit.Pixel);
// Dispose to free up resources
image.Dispose();
bmp.Dispose();
gfx.Dispose();
return bmp;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return null;
}
}
我不认为它的裁切功能那是错误的,但林不知道
哦叶大声笑,它现在的作品,谢谢 – Will