1
我有一個相當大的(30MB)圖像,我想從中取出一小塊「切片」。切片需要表示原始圖像的旋轉部分。GDI +旋轉的子圖像
下面的工程,但角落是空的,它似乎是我採取原始圖像的矩形區域,然後旋轉,並繪製在未旋轉的表面上導致缺少的角落。
我想要的是原始圖像上的旋轉選擇,然後繪製在未旋轉的表面上。我知道我可以先旋轉原始圖像來完成此操作,但考慮到它的大小,這似乎效率低下。
有什麼建議嗎?謝謝,
public Image SubImage(Image image, int x, int y, int width, int height, float angle)
{
var bitmap = new Bitmap(width, height);
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.TranslateTransform(bitmap.Width/2.0f, bitmap.Height/2.0f);
graphics.RotateTransform(angle);
graphics.TranslateTransform(-bitmap.Width/2.0f, -bitmap.Height/2.0f);
graphics.DrawImage(image, new Rectangle(0, 0, width, height), x, y, width, height, GraphicsUnit.Pixel);
}
return bitmap;
}
已經登陸opiton 2.沒有測試性能,但它確定似乎會更快。 – andleer