ASP.Net GDI+
[40 mn de lecture - paru le 5/8/2004 1:54:12 PM - Public : Confirmé]
|
   
|
Auteur
5. To swivel the image
5.1. Rotation and Flip
Rotation is a common operation in many programs of Image. Rotation turns an image under an angle which is a multiple of 90. Flip reflects an image on an axis. The method of RotateFlip enables us to turn and reverse images. The value of RotateFlip is enumeration of RotateFlipType, which defines the direction of rotation and Flip. To turn and/or reverse an image, a RotateFlip call is enough.
Thanks to the RotateFlip method you will be able to carry out rotations of 90,180 and 270 degrees. But also of effect Miroir(Flip).Le table below counts the members of the RotateFlip method. It is easy to include/understand the members of the enumeration of RotateFlipType:
Member |
Description |
Rotate180FlipNone |
rotation180-degrees but without Flip |
Rotate180FlipX |
rotation 180-degrees with flip horizontal |
Rotate180FlipXY |
rotation 180-degrees with flip horizontal and vertical |
Rotate180FlipY |
rotation180-degrees with flip vertical |
Rotate270FlipNone |
rotation270-degrees without flip |
Rotate270FlipX |
rotation270-degrees with flip horizontal |
Rotate270FlipXY |
rotation270-degrees with flip horizontal and vertical |
Rotate270FlipY |
rotation270-degrees with flip vertical |
Rotate90FlipNone |
rotation90-degrees without flip |
Rotate90FlipX |
rotation90-degrees with flip horizontal |
Rotate90FlipXY |
rotation90-degrees with flip horizontal and vertical |
Rotate90FlipY |
rotation90-degrees with flip vertical |
RotateNoneFlipNone |
Not rotation and without flip |
RotateNoneFlipX |
Not rotation, with flip horizontal |
RotateNoneFlipXY |
Not rotation, with flip horizontal and vertical |
RotateNoneFlipY |
Not rotation, with flip vertical |
We will take that the members who can be interesting 90 degrees right-hand side and left as well as a mirror effect for made up a Rotation method:
/// <summary>
/// rotated image
/// </summary>
public void rotation(int angleDeRotation)
{
switch(angleDeRotation)
{
case 90 : theImage.RotateFlip(RotateFlipType.Rotate90FlipXY); break;
case 180 : theImage.RotateFlip(RotateFlipType.Rotate270FlipXY); break;
default : theImage.RotateFlip(RotateFlipType.RotateNoneFlipX); break;
}
}
5.2. False effect 3d
I call this method distorts 3d because I deform the image in 3 points in space
/// <summary>
/// distorts 3D
/// </summary>
public void fausse3D()
{
Point[] pts =
{
new Point(65, 65),// dot creatre with X et Y
new Point(300, 0),
new Point(400, 400)
};
//
to create the new image in which one will make the treatment
Bitmap tempImage = new Bitmap( monImage.Width,
monImage.Height, monImage.PixelFormat);
Graphics g = Graphics.FromImage(tempImage);
//
prime coat
g.Clear(System.Drawing.Color.White);
//
executions of the effect
g.DrawImage(monImage,
pts);
// dispose les ressources
g.Dispose();
monImage.Dispose();
//
one attribute the new image in that of origin
monImage = tempImage;
}
5.3. Call of the method of rotation
private void rotation1_Click(object sender, System.EventArgs e)
{
String path = ImageButton1.ImageUrl.Replace("file:///","").ToString();
//
instanciation of the class traitementImage
traitementImage monImage = new traitementImage();
// load image
monImage.chargementImage(path);
//
call the method and one passes in parameter is 90,180 or 0
monImage.rotation(90);
String nouveaNom = Server.MapPath(Request.ApplicationPath) + "/miniaturePhoto.JPG";
//
save as image under a new name
monImage.SaveImageAs(nouveaNom);
//
reloads the image in the page
Imagebutton2.ImageUrl = Server.MapPath(Request.ApplicationPath) + "/miniaturePhoto.JPG";
}
| ORIGINALE |
FLIP |
Rotated 90 left |
Rotated 90 right |
 |
 |
 |
 |
5.4. Call to the method Distorts 3d
private void rotation1_Click(object sender, System.EventArgs e)
{
String path = ImageButton1.ImageUrl.Replace("file:///","").ToString();
//
instanciation of the class traitementImage
traitementImage monImage = new traitementImage();
//
loading of the image
monImage.chargementImage(path);
//
call the method 3d is distorted
monImage.fausse3D();
String nouveaNom = Server.MapPath(Request.ApplicationPath) + "/miniaturePhoto.JPG";
//
recording of the image under a new name
monImage.SaveImageAs(nouveaNom);
//
reloads the image in the page
Imagebutton2.ImageUrl = Server.MapPath(Request.ApplicationPath) + "/miniaturePhoto.JPG";
}
| ORIGINALE |
DISTORTS |
 |
 |
|