ASP.Net GDI+
[40 mn de lecture - paru le 5/8/2004 1:54:12 PM - Public : Confirmé]
|
   
|
Auteur
6. Modification by Pixels
Let us go always further in the handling of the images.
6.1. Resolutions
GDI+ also enables you to modify the resolution of an image. You must use the SetResolution method which takes in parameter the vertical resolution and the horizontal resolution
/// <summary>
/// change resolution of image
/// </summary>
public void resolution(float nouvelleResolution)
{
//
creation of an image to the same dimension that the image source
Bitmap tempImage = new Bitmap(monImage);
int W=tempImage.Width, H=tempImage.Height;
//
one course the image pixel by pixel to modify each one of them
for (int li=0; li<H; li++)
for (int col=0; col<W; col++)
{
tempImage.SetResolution(nouvelleResolution,nouvelleResolution);
}
monImage.Dispose();
monImage = tempImage;
}
6.2. Transparency
We will put a filter or rather an image, here a rectangle yellow and given to him a tiny opacity.
/// <summary>
/// filter transparent
/// </summary>
public void transparence(string chemin)
{
//
one creates the image since an existing image
Bitmap curImage = new Bitmap(monImage);
Graphics g =Graphics.FromImage(curImage);
//
// the image is drawn
g.DrawImage(curImage, 0, 0, curImage.Width, curImage.Height);
//
one creates an object with different opacity
SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(60, 255, 255, 0));
//
drawing of the graphic with the transparency
g.FillRectangle(semiTransBrush, 0, 0, curImage.Width, curImage.Height);
monImage.Dispose();
monImage = curImage;
}
| FONT |
AFTER |
 |
 |
6.3. Black and White
For the transformation black and white of an image, you have several possibilities. We go utlized the method pixels by pixels. Will know that this method is long and that it can required several seconds for large files
/// <summary>
/// transformation black and white
/// </summary>
public void noirBlanc()
{
//
creation of an image to the same dimension that the image source
Bitmap tempImage = new Bitmap(monImage);
int W=tempImage.Width, H=tempImage.Height;
//
course the image to modify pixel by pixel
for (int li=0; li<H; li++)
for (int col=0; col<W; col++)
{
Color c = tempImage.GetPixel(col, li);
int gris = (c.R + c.G + c.B)/3;//
definite the gray color
tempImage.SetPixel(col, li, Color.FromArgb(gris, gris, gris));//
definite the gray color
}
monImage.Dispose();//
dispose resources of the image source
monImage = tempImage;//
attribute with the image source the new image
}
| ORIGINALE |
BLACK& WHITE |
 |
 |
|