我想裁剪位圖使用此功能,但該位圖可以更小,則作物的種植面積,所以我想在這種情況下,位圖大。裁剪位圖和擴大規模,如果必要
如實例我有一個位圖,其是200x250,如果我使用CropBitmap方法用250x250的我得到一個內存不足的錯誤。它應該返回一個250x250的位圖,其中缺少的左側50像素用白色填充。
我該如何做到這一點?
public Bitmap CropBitmap(Bitmap bitmap, int cropX, int cropY, int cropWidth, int cropHeight)
{
var rect = new Rectangle(cropX, cropY, cropWidth, cropHeight);
if(bitmap.Width < cropWidth || bitmap.Height < cropHeight)
{
// what now?
}
return bitmap.Clone(rect, bitmap.PixelFormat);
}
這可能有助於調整大小需求:http://snippets.dzone.com/posts/show/4336 – ThePower