Color.FromArgb, méthode (Int32, Int32, Int32) (System.Drawing)

Bibliothèque de classes .NET Framework 
Color.FromArgb, méthode (Int32, Int32, Int32) 

Crée une structure Color à partir des valeurs de couleurs 8 bits spécifiées (rouge, vert et bleu). La valeur alpha est implicitement égale à 255 (entièrement opaque). Bien que cette méthode permette de passer une valeur 32 bits pour chaque composant de couleur, leur valeur est limitée à 8 bits.

Espace de noms : System.Drawing
Assembly : System.Drawing (dans system.drawing.dll)

SyntaxeSyntaxe


Visual Basic (Déclaration)
Public Shared Function FromArgb ( _
    red As Integer, _
    green As Integer, _
    blue As Integer _
) As Color


Visual Basic (Utilisation)
Dim red As Integer
Dim green As Integer
Dim blue As Integer
Dim returnValue As Color

returnValue = Color.FromArgb(red, green, blue)


C#
public static Color FromArgb (
    int red,
    int green,
    int blue
)


C++
public:
static Color FromArgb (
    int red, 
    int green, 
    int blue
)


J#
public static Color FromArgb (
    int red, 
    int green, 
    int blue
)


JScript
public static function FromArgb (
    red : int, 
    green : int, 
    blue : int
) : Color

Paramètres

red

Valeur du composant rouge du nouveau Color. Les valeurs autorisées sont comprises entre 0 et 255.

green

Valeur du composant vert du nouveau Color. Les valeurs autorisées sont comprises entre 0 et 255.

blue

Valeur du composant bleu du nouveau Color. Les valeurs autorisées sont comprises entre 0 et 255.

Valeur de retour

Color créé par cette méthode.
ExceptionsExceptions
Type d'exceptionCondition

ArgumentException

red, green ou blue est inférieur à 0 ou supérieur à 255.

ExempleExemple

L'exemple de code suivant est destiné à être utilisé avec Windows Forms et nécessite PaintEventArgse, qui est un paramètre du gestionnaire d'événements Paint. Le code exécute les actions suivantes :

  1. Crée des structures Color à partir des valeurs des trois composants de couleur (rouge, vert et bleu). Trois structures Color sont créées, à raison d'une par couleur primaire.

  2. Parcourt une plage de valeurs alpha, modifiant la valeur alpha d'une couleur.

  3. Durant chaque itération, affecte la couleur modifiée à la couleur d'un pinceau et peint un rectangle pour afficher cette couleur.

  4. Répète les étapes 2 et 3 pour chaque couleur primaire.

La valeur alpha n'est jamais entièrement opaque et les rectangles se chevauchent, produisant des effets de fusion de couleurs.



Visual Basic
Public Sub FromArgb2(ByVal e As PaintEventArgs)
    Dim g As Graphics = e.Graphics

    ' Opaque colors (alpha value defaults to 255 -- max value).
    Dim red As Color = Color.FromArgb(255, 0, 0)
    Dim green As Color = Color.FromArgb(0, 255, 0)
    Dim blue As Color = Color.FromArgb(0, 0, 255)

    ' Solid brush initialized to red.
    Dim myBrush As New SolidBrush(red)
    Dim alpha As Integer

    ' x coordinate of first red rectangle.
    Dim x As Integer = 50

    ' y coordinate of first red rectangle.
    Dim y As Integer = 50

    ' Fill rectangles with red, varying the alpha value from 25 to 250.
    For alpha = 25 To 250 Step 25
        myBrush.Color = Color.FromArgb(alpha, red)
        g.FillRectangle(myBrush, x, y, 50, 100)
        g.FillRectangle(myBrush, x, y + 250, 50, 50)
        x += 50
    Next alpha

    ' x coordinate of first green rectangle.
    x = 50

    ' y coordinate of first green rectangle.
    y += 50


    ' Fill rectangles with green, varying alpha value from 25 to 250.
    For alpha = 25 To 250 Step 25
        myBrush.Color = Color.FromArgb(alpha, green)
        g.FillRectangle(myBrush, x, y, 50, 150)
        x += 50
    Next alpha

    ' x coordinate of first blue rectangle.
    x = 50

    ' y coordinate of first blue rectangle.
    y += 100

    ' Fill rectangles with blue, varying alpha value from 25 to 250.
    For alpha = 25 To 250 Step 25
        myBrush.Color = Color.FromArgb(alpha, blue)
        g.FillRectangle(myBrush, x, y, 50, 150)
        x += 50
    Next alpha
End Sub


C#
public void FromArgb2(PaintEventArgs e)
{
    Graphics     g = e.Graphics;
             
    // Opaque colors (alpha value defaults to 255 -- max value).
    Color red = Color.FromArgb(255, 0, 0);
    Color green = Color.FromArgb(0, 255, 0);
    Color blue = Color.FromArgb(0, 0, 255);
             
    // Solid brush initialized to red.
    SolidBrush  myBrush = new SolidBrush(red);
    int alpha;

    // x coordinate of first red rectangle
    int x = 50;         
    
    // y coordinate of first red rectangle
    int y = 50;         
                   
    // Fill rectangles with red, varying the alpha value from 25 to 250.
    for (alpha = 25; alpha <= 250; alpha += 25)
    {
        myBrush.Color = Color.FromArgb(alpha, red);
        g.FillRectangle(myBrush, x, y, 50, 100);
        g.FillRectangle(myBrush, x, y + 250, 50, 50);
        x += 50;
    }
    // x coordinate of first green rectangle.
    x = 50;             
    
    // y coordinate of first green rectangle.
    y += 50;            
                      
    // Fill rectangles with green, varying the alpha value from 25 to 250.
    for (alpha = 25; alpha <= 250; alpha += 25)
    {
        myBrush.Color = Color.FromArgb(alpha, green);
        g.FillRectangle(myBrush, x, y, 50, 150);
        x += 50;
    }
    // x coordinate of first blue rectangle.
    x = 50;             
    
    // y coordinate of first blue rectangle.
    y += 100;           
             
    // Fill rectangles with blue, varying the alpha value from 25 to 250.
    for (alpha = 25; alpha <= 250; alpha += 25)
    {
        myBrush.Color = Color.FromArgb(alpha, blue);
        g.FillRectangle(myBrush, x, y, 50, 150);
        x += 50;
    }
}


C++
void FromArgb2( PaintEventArgs^ e )
{
   Graphics^ g = e->Graphics;

   // Opaque colors (alpha value defaults to 255 -- max value).
   Color red = Color::FromArgb( 255, 0, 0 );
   Color green = Color::FromArgb( 0, 255, 0 );
   Color blue = Color::FromArgb( 0, 0, 255 );

   // Solid brush initialized to red.
   SolidBrush^ myBrush = gcnew SolidBrush( red );
   int alpha;

   // x coordinate of first red rectangle
   int x = 50;

   // y coordinate of first red rectangle
   int y = 50;

   // Fill rectangles with red, varying the alpha value from 25 to 250.
   for ( alpha = 25; alpha <= 250; alpha += 25 )
   {
      myBrush->Color = Color::FromArgb( alpha, red );
      g->FillRectangle( myBrush, x, y, 50, 100 );
      g->FillRectangle( myBrush, x, y + 250, 50, 50 );
      x += 50;
   }
   x = 50;

   // y coordinate of first green rectangle.
   y += 50;

   // Fill rectangles with green, varying the alpha value from 25 to 250.
   for ( alpha = 25; alpha <= 250; alpha += 25 )
   {
      myBrush->Color = Color::FromArgb( alpha, green );
      g->FillRectangle( myBrush, x, y, 50, 150 );
      x += 50;
   }
   x = 50;

   // y coordinate of first blue rectangle.
   y += 100;

   // Fill rectangles with blue, varying the alpha value from 25 to 250.
   for ( alpha = 25; alpha <= 250; alpha += 25 )
   {
      myBrush->Color = Color::FromArgb( alpha, blue );
      g->FillRectangle( myBrush, x, y, 50, 150 );
      x += 50;
   }
}


J#
public void FromArgb2(PaintEventArgs e)
{
    Graphics g = e.get_Graphics();

    // Opaque colors (alpha value defaults to 255 -- max value).
    Color red = Color.FromArgb(255, 0, 0);
    Color green = Color.FromArgb(0, 255, 0);
    Color blue = Color.FromArgb(0, 0, 255);

    // Solid brush initialized to red.
    SolidBrush myBrush = new SolidBrush(red);
    int alpha;

    // x coordinate of first red rectangle
    int x = 50;

    // y coordinate of first red rectangle
    int y = 50;

    // Fill rectangles with red, varying the alpha value from 25 to 250.
    for (alpha = 25; alpha <= 250; alpha+=25) {
        myBrush.set_Color(Color.FromArgb(alpha, red));
        g.FillRectangle(myBrush, x, y, 50, 100);
        g.FillRectangle(myBrush, x, y + 250, 50, 50);
        x += 50;
    }

    // x coordinate of first green rectangle.
    x = 50;

    // y coordinate of first green rectangle.
    y+=50;

    // Fill rectangles with green, varying the alpha value from 25 to 250.
    for (alpha = 25; alpha <= 250; alpha+=25) {
        myBrush.set_Color(Color.FromArgb(alpha, green));
        g.FillRectangle(myBrush, x, y, 50, 150);
        x += 50;
    }

    // x coordinate of first blue rectangle.
    x = 50;

    // y coordinate of first blue rectangle.
    y += 100;

    // Fill rectangles with blue, varying the alpha value from 25 to 250.
    for (alpha = 25; alpha <= 250; alpha+=25) {
        myBrush.set_Color(Color.FromArgb(alpha, blue));
        g.FillRectangle(myBrush, x, y, 50, 150);
        x += 50;
    }
} //FromArgb2
Plates-formesPlates-formes

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition

Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.

Informations de versionInformations de version

.NET Framework

Prise en charge dans : 2.0, 1.1, 1.0

.NET Compact Framework

Prise en charge dans : 2.0, 1.0
Voir aussiVoir aussi

Ces informations proviennent du site de http://msdn2.microsoft.com
Source de cette page : http://msdn2.microsoft.com/fr-fr/library/cce5h557.aspx

Réseaux sociaux

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.

 

Nuage de mots clés

10 mots clés dont 0 définis manuellement (plus d'information...).

Avertissement

Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.

 

Astuce pour imprimer les couleurs des cellules de tableaux : http://www.gaudry.be/ast-rf-450.html
Aucun commentaire pour cette page

© Ce document issu de l′infobrol est enregistré sous le certificat Cyber PrInterDeposit Digital Numbertection. Enregistrement IDDN n° 5329-6966
Document créé le 07/11/06 23:24, dernière modification le Vendredi 17 Juin 2011, 12:11
Source du document imprimé : http://www.gaudry.be/dotnet-rf-cce5h557.html Document affiché 6 fois ce mois de Mai.
St.Gaudry©07.01.02
Outils (masquer)
||
Recherche (afficher)
Recherche :

Utilisateur (masquer)
Navigation (masquer)
Apparence (afficher)
Stats (afficher)
15832 documents
452 astuces.
549 niouzes.
3099 definitions.
447 membres.
8115 messages.

Document genere en :
0,52 seconde

Mises à jour :
Mises à jour du site
Citation (masquer)
Plus la part de gâteau est belle, plus elle a de chance de tomber de travers dans l'assiette au moment de la servir.

Loi de Murphy
 
l'infobrol
Nous sommes le Jeudi 31 Mai 2012, 12:20, toutes les heures sont au format GMT+1.00 Heure, heure d'été (+1)