1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
/* Convert RGB To HSB Color Example This java example shows how to convert Red,Green, and Blue (RGB) to Hue, Saturation, and brightness model (HSB) using Java AWT Color class. */ import java.applet.Applet; import java.awt.Color; import java.awt.Graphics; /* <applet code="ConvertRGBToHSBColor" width=400 height=100> </applet> */ public class ConvertRGBToHSBColor extends Applet{ public void paint(Graphics g){ /* * To convert RGB to HSB, use * static float[] RGBtoHSB(int r, int g, int b, float[] hsbValues) * method of AWT Color class. * * This method converts RGB components to it's equivalent HSB values. * * If hsbValues array is null, new array will be created and returned, * otherwise the same array will be returned with the HSB values. * * This method returns an array of three elements having hue at first index, * saturation at second and brightness at third index. * . */ float[] hsbValues = new float[3]; hsbValues = Color.RGBtoHSB(255,10,10,hsbValues); float hue, saturation, brightness; hue = hsbValues[0]; saturation = hsbValues[1]; brightness = hsbValues[2]; g.drawString("Hue: " + hue + ", Saturation:" + saturation + ", Brightness:" + brightness,10,50); } } |
Example Output
Add Comment