c# et gdi+ ont un moyen simple de contrôler les couleurs qui sont dessinés.
C'est essentiellement un ColorMatrix. C'est un 5×5 de la matrice qui est appliqué à
chaque couleur si elle est définie. Réglage de la luminosité est tout simplement l'exécution d'une
traduire sur les données de couleur et le contraste est d'effectuer une échelle sur le
couleur. Gamma est une toute autre forme de transformation, mais il est inclus
dans ImageAttributes qui accepte le ColorMatrix.
Bitmap originalImage;Bitmap adjustedImage;float brightness =1.0f;//no change in brightnessfloat contrast =2.0f;//twice the contrastfloat gamma =1.0f;//no change in gammafloat adjustedBrightness = brightness -1.0f;//create matrix that will brighten and contrast the imagefloat[][] ptsArray ={newfloat[]{contrast,0,0,0,0},//scale rednewfloat[]{0, contrast,0,0,0},//scale greennewfloat[]{0,0, contrast,0,0},//scale bluenewfloat[]{0,0,0,1.0f,0},//don't scale alphanewfloat[]{adjustedBrightness, adjustedBrightness, adjustedBrightness,0,1}};ImageAttributes imageAttributes =newImageAttributes();
imageAttributes.ClearColorMatrix();
imageAttributes.SetColorMatrix(newColorMatrix(ptsArray),ColorMatrixFlag.Default,ColorAdjustType.Bitmap);
imageAttributes.SetGamma(gamma,ColorAdjustType.Bitmap);Graphics g =Graphics.FromImage(adjustedImage);
g.DrawImage(originalImage,newRectangle(0,0,adjustedImage.Width,adjustedImage.Height),0,0,originalImage.Width,originalImage.Height,GraphicsUnit.Pixel, imageAttributes);
OriginalL'auteur VladL