Crop Bitmap clone with pictureBox sizeMode is zoomed

Viewed 1734

I find this function on the internet to crop image, it doing fine if the pictureBox source sizeMode is normal. But when the pictureBox sizeMode is zoom its still cloned like the normal sizeMode.

How to clone same as the zoomed pictureBox? not the size of original normal bitmap?

public static Bitmap CropBitmap(Bitmap bitmap, int x, int y, int w, int h)
{
    Rectangle rect = new Rectangle(x, y, w, h);
    Bitmap cropped = bitmap.Clone(rect, bitmap.PixelFormat);
    return cropped;
}

and used like this

pictureBox2.Image = CropBitmap((Bitmap)pictureBox1.Image.Clone(), 35, 0, 110, 150);
1 Answers
Related