1. currentrgbcolor
Returns current color as RGB values.
1.2. Stack Effects
| Level | Object |
|---|---|
(empty) |
– |
| Level | Object |
|---|---|
2 |
|
1 |
|
0 |
|
1.3. Description
currentrgbcolor returns the current color in the graphics state according to the red-green-blue color model.
-
If the current color space is DeviceRGB,
currentrgbcolorreturns the color values most recently specified tosetrgbcoloror [setcolor] (or transformed values specified tosethsbcolor) . -
If the current color space is DeviceGray or DeviceCMYK,
currentrgbcolorconverts the current color to RGB. -
For any other color space,
currentrgbcolorreturns 0.0 0.0 0.0 (black).
Each returned value is in the range 0.0 (no intensity) to 1.0 (full intensity).
1.5. Examples
1 0 0 setrgbcolor % Red
currentrgbcolor
% Stack: 1.0 0.0 0.0
currentrgbcolor % Save current
/blue exch def
/green exch def
/red exch def
0.5 0.5 0 setrgbcolor % Change to olive
drawShape
red green blue setrgbcolor % Restore
0.5 setgray
currentrgbcolor
% Stack: 0.5 0.5 0.5
currentrgbcolor
3 -1 roll % Rotate R to top
0.5 mul % Darken red
3 1 roll % Rotate back
setrgbcolor
1.6. Common Use Cases
1.6.1. Color State Preservation
/SaveColor {
currentrgbcolor
/savedBlue exch def
/savedGreen exch def
/savedRed exch def
} def
/RestoreColor {
savedRed savedGreen savedBlue setrgbcolor
} def
1.6.2. Color Modification
/DarkenColor {
currentrgbcolor
0.5 mul 3 1 roll
0.5 mul 3 1 roll
0.5 mul 3 1 roll
setrgbcolor
} def
1.7. Common Pitfalls
| Color Space Conversion - Converting from CMYK to RGB may not preserve exact colors. |
0 1 1 0 setcmykcolor % Cyan in CMYK
currentrgbcolor % Converted to RGB
setrgbcolor % Now in RGB space
% May not match original cyan exactly
| Returns Black for Unknown Spaces - Pattern and other color spaces return 0 0 0. |
/Pattern setcolorspace
myPattern setcolor
currentrgbcolor % Returns 0 0 0
| Stack Order - Remember RGB order: red at level 2, blue at level 0. |
currentrgbcolor
% Stack (bottom to top): red green blue
% Pop order: blue, green, red
| Use Array for Storage - Simplifies color management. |
[ currentrgbcolor ] /myColor exch def
myColor aload pop setrgbcolor
1.9. Implementation Notes
-
Fast query operation
-
No modification to graphics state
-
Values always in range 0.0 to 1.0
-
Conversion preserves visual appearance
-
Widely supported (Level 1)
1.10. Color Conversion
When converting from other color spaces:
red = green = blue = grayValue
red = (1 - cyan) × (1 - black) green = (1 - magenta) × (1 - black) blue = (1 - yellow) × (1 - black)
(Internal conversion - HSB is just RGB entry method)
red = green = blue = 0.0
1.11. RGB Color Model
The RGB color model is additive:
Red + Green = Yellow
Red + Blue = Magenta
Green + Blue = Cyan
R + G + B = White
No components = Black
1.12. See Also
-
setrgbcolor- Set RGB color -
currentgray- Get gray value -
currentcmykcolor- Get CMYK color (Level 2) -
currenthsbcolor- Get HSB color