4/5 (3 avis)
Vue 8 089 fois - Téléchargée 585 fois
#region GetDiffusedBitmap (création d'une image diffuse) /// <summary> /// Retourne une image diffuse. /// </summary> /// <param name="img">Image d'origine.</param> /// <param name="direction">Sens de la diffusion.</param> /// <returns>Image diffusée.</returns> public static Bitmap GetDiffusedBitmap(Image img, dbm_Direction direction) { float stepFactor = 0.01f; float alphaFactor = stepFactor; float alpha = 1.0f; int step = 0; if (direction == dbm_Direction.Right || direction == dbm_Direction.Left) step = (int)(img.Width*stepFactor); else step = (int)(img.Height*stepFactor); int x = 0; if (direction == dbm_Direction.Left) x = img.Width - step; else if (direction == dbm_Direction.Top) x = img.Height - step; ColorMatrix cm = new ColorMatrix(); cm.Matrix33 = alpha; ImageAttributes ia = new ImageAttributes(); ia.SetColorMatrix( cm, ColorMatrixFlag.Default, ColorAdjustType.Bitmap ); Bitmap bmp = new Bitmap(img.Width, img.Height); using (Graphics g = Graphics.FromImage(bmp)) { while (cm.Matrix33 >= 0.0f) { Rectangle rect = Rectangle.Empty; if (direction == dbm_Direction.Right || direction == dbm_Direction.Left) rect = new Rectangle(x, 0, step, img.Height); else rect = new Rectangle(0, x, img.Width, step); g.DrawImage( img, rect, rect.X, rect.Y, rect.Width, rect.Height, GraphicsUnit.Pixel, ia ); if (direction == dbm_Direction.Right || direction == dbm_Direction.Bottom) x += step; else if (direction == dbm_Direction.Left || direction == dbm_Direction.Top) x -= step; alpha -= alphaFactor; cm.Matrix33 = alpha; ia.SetColorMatrix( cm, ColorMatrixFlag.Default, ColorAdjustType.Bitmap ); } } return bmp; } #endregion #region dbm_Direction public enum dbm_Direction : short { /// <summary> /// Vers la droite. /// </summary> Right = 0, /// <summary> /// Vers la gauche. /// </summary> Left = 1, /// <summary> /// Vers le haut. /// </summary> Top = 2, /// <summary> /// Vers le bas. /// </summary> Bottom = 3 } #endregion
11 juil. 2005 à 19:55
11 juil. 2005 à 15:12
6 juil. 2005 à 22:37
Je ne savais pas que c'était "si simple" de faire quelque chose comme ça... Enfin, encore faut-il connaître les classes ColorMatrixFlag, ColorMatrix et ImageAttributes...
Bonne source.
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.