0

I have a picture box of size 492*522.And it's properties are set as below.

BackgroundLayoutImage = Stretch, Sizemode = Stretch Image.

Now I want to display the  first half portion of the bitmap in it. With a vertical crop (Y value) of 200. Means 200 should be removed from the top portion of bitmap. I have done it like below.  

Rectangle section = new Rectangle(new Point(0, 200), new Size(image.Width / 2, image.Height));
FirstHalf = CropImage(FirstHalf, section);
pictureBox1.Image = FirstHalf;
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;
            }
        }

But now the size of the picturebox reduces. And it does not give a stretchable look. I want the size of the picture box to 492*522 itself. And should get a stretchable look when cropping 200 from bitmap. How can I achieve this? Please help.

user2431727
  • 877
  • 2
  • 15
  • 46
  • 1
    Then use the same size of the source image to create the new one and use the same source and destination regions. i.e. `new Rectangle(0, 200, src.Width, src.Height - h);`. What are you going to do with that region? Apply some filter? Otherwise no visual impact. And fix this line `FirstHalf = CropImage(FirstHalf, section);` in your code. And what the `asp.net` tag is doing here? – dr.null May 07 '21 at 17:14
  • new Rectangle(0, 200, src.Width, src.Height - h);. This made my day! – user2431727 May 10 '21 at 04:56

0 Answers0