Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Utilisé pour réécrire chaque pixel d'une image.
- //
- // Used to rewrite each pixel of an image.
- public static Bitmap fixLimitedColor(Bitmap bitmap) {
- int redValue = 0;
- int blueValue = 0;
- int greenValue = 0;
- int pixel = 0;
- for (int i = 0; i < bitmap.getHeight() - 1; i++) {
- for (int j = 0; j < bitmap.getWidth() - 1; j++) {
- pixel = bitmap.getPixel(j, i);
- redValue = Color.red(pixel);
- blueValue = Color.blue(pixel);
- greenValue = Color.green(pixel);
- redValue = fixValue(redValue);
- blueValue = fixValue(blueValue);
- greenValue = fixValue(greenValue);
- bitmap.setPixel(j, i, Color.rgb(redValue, greenValue, blueValue));
- }
- }
- return bitmap;
- }
- // Ecreteur de valeur, chaque couleur ne peux plus avoir que 5 valeur différentes.
- // Ce qui donne un total d'environs 125 valeur de couleur diffentes (RGB)
- //
- // Value scaler, each color can only have 5 different value.
- // Which is giving a total of 125 uniques color in RGB.
- private static int fixValue(int colorValue) {
- int minTol = 10;
- int min = 0;
- int max = 255;
- int medium = 128;
- int quarter = 64;
- if (colorValue < quarter) {
- colorValue = min;
- } else if (colorValue < medium) {
- colorValue = quarter;
- } else if (colorValue < medium + quarter) {
- colorValue = medium;
- } else if (colorValue < max - minTol) {
- colorValue = medium + quarter;
- } else {
- colorValue = max;
- }
- return colorValue;
- }
Add Comment
Please, Sign In to add comment