7. แถวลำดับ

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 7-38  เมท็อดให้บริการดึงแม่สีและผสมแม่สี
public class DWindow {
  ...
  public static int getR(int c) {
    return (c >> 16) & 0xFF;
  }
  public static int getG(int c) {
    return (c >> 8) & 0xFF;
  }
  public static int getB(int c) {
    return c & 0xFF;
  }
  public static int mixRGB(int r, int g, int b) {
    return 0xFF000000 | (clip(r)<<16) | (clip(g)<<8) | clip(b);
  }
  private static int clip(int v) { // ปัดค่าของ v ให้อยู่ในช่วง 0 - 255
    if (v < 0) v = 0;
    if (v > 255) v = 255;
    return v;
  }
  ...
©2009 S.Prasitjutrakul