Color class

Color class

Represents an ARGB (alpha, red, green, blue) color. Compatible with .NET System.Drawing.Color.

The Color type exposes the following members:

Constructors

ConstructorDescription
__init__(self, r=0, g=0, b=0, a=255)Creates a color from the specified red, green, blue and alpha component values.

Properties

PropertyDescription
aGets the alpha component value of this color.
Read-only int.
rGets the red component value of this color.
Read-only int.
gGets the green component value of this color.
Read-only int.
bGets the blue component value of this color.
Read-only int.
nameGets the name of this color.
For a named color (a named constant such as Color.red, or a color created with from_name) the .NET name is returned, e.g. "Red" or "LightBlue".
For any other color the ARGB value is returned as lowercase hexadecimal without zero padding, e.g. "ffff0000". Color.empty.name is "0".
Read-only str.
is_emptySpecifies whether this color is Color.empty.
Returns False for a color with all components equal to zero created with from_argb.
Read-only bool.
is_known_colorSpecifies whether this color is one of the predefined .NET KnownColor colors (a named color or a system color).
Read-only bool.
is_named_colorSpecifies whether this color carries a name: it was created from a named constant such as Color.red, with from_name, or was returned from the library as a named color.
Read-only bool.
is_system_colorSpecifies whether this color is a system color: a color used for a Windows display element, such as Control or ActiveBorder.
System colors are not exposed as Color attributes and can only be obtained with from_known_color or returned from the library.
Read-only bool.

Methods

MethodDescription
from_argb(argb)Creates a color from a 32-bit ARGB value.
from_argb(alpha, base_color)Creates a color from the specified alpha value and base color.
from_argb(red, green, blue)Creates an opaque color (alpha is 255) from the specified red, green and blue values.
from_argb(alpha, red, green, blue)Creates a color from the four ARGB component (alpha, red, green, and blue) values.
from_known_color(known_color)Creates a color from the specified predefined color.
from_name(name)Creates a color from the specified name of a predefined color.
from_rgb(r, g, b)Creates an opaque color (alpha is 255) from the specified red, green and blue values.
get_brightness(self)Gets the hue-saturation-lightness (HSL) lightness value for this color.
get_hue(self)Gets the hue-saturation-lightness (HSL) hue value, in degrees, for this color.
get_saturation(self)Gets the hue-saturation-lightness (HSL) saturation value for this color.
to_argb(self)Gets the 32-bit ARGB value of this color.
to_known_color(self)Gets the KnownColor value of this color.
to_string(self)Converts this color to a human-readable string. The same text is returned by str() and repr().

Remarks

Colors are compared by their ARGB components with == and can be used as dictionary keys or set members.

The predefined colors (the 141 named .NET KnownColor colors, Color.transparent and Color.empty) are available as class attributes spelled in snake_case, for example Color.red, Color.light_blue or Color.dark_slate_gray (see Named colors below). They can also be called like methods (Color.red()), which returns the same color.

Examples

import aspose.slides as slides

with slides.Presentation() as pres:
    shape = pres.slides[0].shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 50, 200, 100)
    shape.fill_format.fill_type = slides.FillType.SOLID
    shape.fill_format.solid_fill_color.color = slides.Color.from_argb(255, 30, 144, 255)
    shape.line_format.fill_format.solid_fill_color.color = slides.Color.dark_blue

    color = slides.Color.from_name("light_blue")
    print(color.name, color.to_argb(), color.is_named_color)  # LightBlue -5383962 True
    print(slides.Color(255, 0, 0) == slides.Color.red)         # True

Named colors

Attribute.NET nameARGB
Color.emptyEmpty00000000
Color.alice_blueAliceBlueFFF0F8FF
Color.antique_whiteAntiqueWhiteFFFAEBD7
Color.aquaAquaFF00FFFF
Color.aquamarineAquamarineFF7FFFD4
Color.azureAzureFFF0FFFF
Color.beigeBeigeFFF5F5DC
Color.bisqueBisqueFFFFE4C4
Color.blackBlackFF000000
Color.blanched_almondBlanchedAlmondFFFFEBCD
Color.blueBlueFF0000FF
Color.blue_violetBlueVioletFF8A2BE2
Color.brownBrownFFA52A2A
Color.burly_woodBurlyWoodFFDEB887
Color.cadet_blueCadetBlueFF5F9EA0
Color.chartreuseChartreuseFF7FFF00
Color.chocolateChocolateFFD2691E
Color.coralCoralFFFF7F50
Color.cornflower_blueCornflowerBlueFF6495ED
Color.cornsilkCornsilkFFFFF8DC
Color.crimsonCrimsonFFDC143C
Color.cyanCyanFF00FFFF
Color.dark_blueDarkBlueFF00008B
Color.dark_cyanDarkCyanFF008B8B
Color.dark_goldenrodDarkGoldenrodFFB8860B
Color.dark_grayDarkGrayFFA9A9A9
Color.dark_greenDarkGreenFF006400
Color.dark_khakiDarkKhakiFFBDB76B
Color.dark_magentaDarkMagentaFF8B008B
Color.dark_olive_greenDarkOliveGreenFF556B2F
Color.dark_orangeDarkOrangeFFFF8C00
Color.dark_orchidDarkOrchidFF9932CC
Color.dark_redDarkRedFF8B0000
Color.dark_salmonDarkSalmonFFE9967A
Color.dark_sea_greenDarkSeaGreenFF8FBC8F
Color.dark_slate_blueDarkSlateBlueFF483D8B
Color.dark_slate_grayDarkSlateGrayFF2F4F4F
Color.dark_turquoiseDarkTurquoiseFF00CED1
Color.dark_violetDarkVioletFF9400D3
Color.deep_pinkDeepPinkFFFF1493
Color.deep_sky_blueDeepSkyBlueFF00BFFF
Color.dim_grayDimGrayFF696969
Color.dodger_blueDodgerBlueFF1E90FF
Color.firebrickFirebrickFFB22222
Color.floral_whiteFloralWhiteFFFFFAF0
Color.forest_greenForestGreenFF228B22
Color.fuchsiaFuchsiaFFFF00FF
Color.gainsboroGainsboroFFDCDCDC
Color.ghost_whiteGhostWhiteFFF8F8FF
Color.goldGoldFFFFD700
Color.goldenrodGoldenrodFFDAA520
Color.grayGrayFF808080
Color.greenGreenFF008000
Color.green_yellowGreenYellowFFADFF2F
Color.honeydewHoneydewFFF0FFF0
Color.hot_pinkHotPinkFFFF69B4
Color.indian_redIndianRedFFCD5C5C
Color.indigoIndigoFF4B0082
Color.ivoryIvoryFFFFFFF0
Color.khakiKhakiFFF0E68C
Color.lavenderLavenderFFE6E6FA
Color.lavender_blushLavenderBlushFFFFF0F5
Color.lawn_greenLawnGreenFF7CFC00
Color.lemon_chiffonLemonChiffonFFFFFACD
Color.light_blueLightBlueFFADD8E6
Color.light_coralLightCoralFFF08080
Color.light_cyanLightCyanFFE0FFFF
Color.light_goldenrod_yellowLightGoldenrodYellowFFFAFAD2
Color.light_grayLightGrayFFD3D3D3
Color.light_greenLightGreenFF90EE90
Color.light_pinkLightPinkFFFFB6C1
Color.light_salmonLightSalmonFFFFA07A
Color.light_sea_greenLightSeaGreenFF20B2AA
Color.light_sky_blueLightSkyBlueFF87CEFA
Color.light_slate_grayLightSlateGrayFF778899
Color.light_steel_blueLightSteelBlueFFB0C4DE
Color.light_yellowLightYellowFFFFFFE0
Color.limeLimeFF00FF00
Color.lime_greenLimeGreenFF32CD32
Color.linenLinenFFFAF0E6
Color.magentaMagentaFFFF00FF
Color.maroonMaroonFF800000
Color.medium_aquamarineMediumAquamarineFF66CDAA
Color.medium_blueMediumBlueFF0000CD
Color.medium_orchidMediumOrchidFFBA55D3
Color.medium_purpleMediumPurpleFF9370DB
Color.medium_sea_greenMediumSeaGreenFF3CB371
Color.medium_slate_blueMediumSlateBlueFF7B68EE
Color.medium_spring_greenMediumSpringGreenFF00FA9A
Color.medium_turquoiseMediumTurquoiseFF48D1CC
Color.medium_violet_redMediumVioletRedFFC71585
Color.midnight_blueMidnightBlueFF191970
Color.mint_creamMintCreamFFF5FFFA
Color.misty_roseMistyRoseFFFFE4E1
Color.moccasinMoccasinFFFFE4B5
Color.navajo_whiteNavajoWhiteFFFFDEAD
Color.navyNavyFF000080
Color.old_laceOldLaceFFFDF5E6
Color.oliveOliveFF808000
Color.olive_drabOliveDrabFF6B8E23
Color.orangeOrangeFFFFA500
Color.orange_redOrangeRedFFFF4500
Color.orchidOrchidFFDA70D6
Color.pale_goldenrodPaleGoldenrodFFEEE8AA
Color.pale_greenPaleGreenFF98FB98
Color.pale_turquoisePaleTurquoiseFFAFEEEE
Color.pale_violet_redPaleVioletRedFFDB7093
Color.papaya_whipPapayaWhipFFFFEFD5
Color.peach_puffPeachPuffFFFFDAB9
Color.peruPeruFFCD853F
Color.pinkPinkFFFFC0CB
Color.plumPlumFFDDA0DD
Color.powder_bluePowderBlueFFB0E0E6
Color.purplePurpleFF800080
Color.rebecca_purpleRebeccaPurpleFF663399
Color.redRedFFFF0000
Color.rosy_brownRosyBrownFFBC8F8F
Color.royal_blueRoyalBlueFF4169E1
Color.saddle_brownSaddleBrownFF8B4513
Color.salmonSalmonFFFA8072
Color.sandy_brownSandyBrownFFF4A460
Color.sea_greenSeaGreenFF2E8B57
Color.sea_shellSeaShellFFFFF5EE
Color.siennaSiennaFFA0522D
Color.silverSilverFFC0C0C0
Color.sky_blueSkyBlueFF87CEEB
Color.slate_blueSlateBlueFF6A5ACD
Color.slate_graySlateGrayFF708090
Color.snowSnowFFFFFAFA
Color.spring_greenSpringGreenFF00FF7F
Color.steel_blueSteelBlueFF4682B4
Color.tanTanFFD2B48C
Color.tealTealFF008080
Color.thistleThistleFFD8BFD8
Color.tomatoTomatoFFFF6347
Color.transparentTransparent00FFFFFF
Color.turquoiseTurquoiseFF40E0D0
Color.violetVioletFFEE82EE
Color.wheatWheatFFF5DEB3
Color.whiteWhiteFFFFFFFF
Color.white_smokeWhiteSmokeFFF5F5F5
Color.yellowYellowFFFFFF00
Color.yellow_greenYellowGreenFF9ACD32

See Also