using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
namespace Developpez.Dotnet.Drawing
{
///
/// Fournit des méthodes d'extension pour la manipulation d'images Bitmap
///
public static class BitmapExtensions
{
///
/// Rogne l'image d'origine en ne conservant que la zone spécifiée, et renvoie la nouvelle image
///
/// L'image à rogner
/// La zone de l'image à conserver
/// L'image rognée
public static Bitmap Crop(this Bitmap bitmap, Rectangle cropRectangle)
{
return bitmap.Clone(cropRectangle, bitmap.PixelFormat);
}
///
/// Rogne l'image d'origine en ne conservant que la zone spécifiée, et renvoie la nouvelle image
///
/// L'image à rogner
/// La zone de l'image à conserver
/// L'image rognée
public static Bitmap Crop(this Bitmap bitmap, RectangleF cropRectangle)
{
return bitmap.Clone(cropRectangle, bitmap.PixelFormat);
}
///
/// Rogne l'image d'origine en ne conservant que la zone spécifiée, et renvoie la nouvelle image
///
/// L'image à rogner
/// La position horizontale de la zone à conserver
/// La position verticale de la zone à conserver
/// La largeur de la zone à conserver
/// La hauteur de la zone à conserver
/// L'image rognée
public static Bitmap Crop(this Bitmap bitmap, int x, int y, int width, int height)
{
Rectangle cropRectangle = new Rectangle(x, y, width, height);
return bitmap.Crop(cropRectangle);
}
///
/// Rogne l'image d'origine en ne conservant que la zone spécifiée, et renvoie la nouvelle image
///
/// L'image à rogner
/// La position horizontale de la zone à conserver
/// La position verticale de la zone à conserver
/// La largeur de la zone à conserver
/// La hauteur de la zone à conserver
/// L'image rognée
public static Bitmap Crop(this Bitmap bitmap, float x, float y, float width, float height)
{
RectangleF cropRectangle = new RectangleF(x, y, width, height);
return bitmap.Crop(cropRectangle);
}
}
}