Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static int colsToInt(int r, int g, int b, int a) { return (Math.max(Math.min(a, 255), 0) << 24) + (Math.max(Math.min(r, 255), 0) << 16) + (Math.max(Math.min(g, 255), 0) << 8) + Math.max(Math.min(b, 255), 0); } public static int colsToInt(int r, int g, int b) { return (255 << 24) + (Math.max(Math.min(r, 255), 0) << 16) + (Math.max(Math.min(g, 255), 0) << 8) + Math.max(Math.min(b, 255), 0); } }