|
Here we draw an image that has been cropped by 100 pixels on
every side. We assume the image is bigger than 200x200.
To do this we use a clip region.
[C#]
using (Image image = Bitmap.FromFile(Server.MapPath("rez/felix-tchverkin-7pkN83wDZwY-unsplash.jpg"))) {
Size inset = new Size(100, 100);
using (Bitmap bm = new Bitmap(image.Size)) {
using (Graphics graphics = Graphics.FromImage(bm)) {
RectangleF rect = bm.Bounds;
rect.Inflate(-inset);
graphics.Clip = new Region(rect);
graphics.DrawImage(image, bm.Bounds);
}
bm.Save(Server.MapPath("IG8_Graphics_Clip.png"));
}
}

felix-tchverkin-7pkN83wDZwY-unsplash.jpg

IG8_Graphics_Clip.png
|