0

I have displayed a bitmap on picturebox with sizemode= stretchimage. Now, I have to crop the top and bottom part of the bitmap and have to display it inside the same picturebox. I have done like below. Cropping works fine. But the cropped image is stretching inside the picturebox. Instead of this stretching, I want to show the cropped bottom and top area in a black color/as empty inside the picturebox. Is it possible? NB: CropVal is ranging from 0 to 50. That is the value I need to crop from bottom and top.

      Bitmap image= new Bitmap(eventArgs.Frame);
Rectangle section = new Rectangle(new Point(0, CropVal), new Size(image.Width, image.Height -2*CropVal));
image= CropImage(image, section);
pictureBox1.Image = image;

     public Bitmap CropImage(Bitmap source, Rectangle section)
    {
        var bitmap = new Bitmap(section.Width, section.Height);
        using (var g = Graphics.FromImage(bitmap))
        {
            g.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel);
            return bitmap;
        }
    }
user2431727
  • 877
  • 2
  • 15
  • 46

0 Answers0