Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
Das hat damit nix zu tun.@LimDul sorry wenn du kein Java kannst.
This is a problem with single-letter variable names. Certainly a loop counter may be
named i or j or k (though never l!) if its scope is very small and no other names can conflict
with it. This is because those single-letter names for loop counters are traditional.
However, in most other contexts a single-letter name is a poor choice; it’s just a place
holder that the reader must mentally map to the actual concept. There can be no worse reason
for using the name c than because a and b were already taken.
In general programmers are pretty smart people. Smart people sometimes like to show
off their smarts by demonstrating their mental juggling abilities. After all, if you can reliably
remember that r is the lower-cased version of the url with the host and scheme
removed, then you must clearly be very smart.
One difference between a smart programmer and a professional programmer is that
the professional understands that clarity is king. Professionals use their powers for good
and write code that others can understand.
Man kann keinen Code schreiben, den alle verstehen können. Das würde voraussetzen, dass es keine dummen Menschen gibt.and write code that others can understand
"dumme Menschen", die zB das Javadoc zu benutzen Funktionen nicht lesen oder nicht verstehen? 😉Das würde voraussetzen, dass es keine dummen Menschen gibt.
Wenn deine Oma Englisch-Sprachig ist und die Domäne kennt, versteht sie "imageWithBird.getRGB(x, y)" sicherlich besser als "b.getRGB(j, i)".Mein Oma würde zum Beispiel b.getRGB(j, i); auch nicht dann verstehen, wenn dort bufferedImage.getRGB(j, i); stünde.
Ja, "b" kann man schneller lesen als "bufferedImage", schneller verstehen aber nicht.Hingegen kann man mit etwas Erfahrung kürzere Variablennamen schneller lesen; das ist einfach die logische Konklusion, da diese kürzer sind, also weniger Buchstaben beinhalten...
So und jetzt nochmal zur Frage zurück... Wie tilge ich den Alphakanal-Wert?
argb & 0x00FFFFFF, sinnvoller ist aber vermutlich anderes, kommt drauf an was du machen möchtest. static float getFloatColor(int rgb) {
// int alpha = (rgb >> 24) & 0xff;
int red = (rgb >> 16) & 0xff;
int green = (rgb >> 8) & 0xff;
int blue = (rgb >> 0) & 0xff;
float[] f = new float[3];
Color.RGBtoHSB(red, green, blue, f);
return f[0];
}
Für einen Bildpunkt einen hash (zwischen 0 und 1) erstellen, wobei Schwarz und Weiß möglichst unterschiedliche hashes ergeben sollen.kommt drauf an was du machen möchtest
static float getFloatColor(int rgb) {
// int alpha = (rgb >> 24) & 0xff;
int r = (rgb >> 16) & 0xff;
int g = (rgb >> 8) & 0xff;
int b = (rgb >> 0) & 0xff;
// Normalize and gamma correct:
double rr = Math.pow(r / 255.0, 2.2);
double gg = Math.pow(g / 255.0, 2.2);
double bb = Math.pow(b / 255.0, 2.2);
// Calculate luminance:
double lum = 0.2126 * rr + 0.7152 * gg + 0.0722 * bb;
// Gamma compand and rescale to byte range:
float grayLevel = (float) Math.pow(lum, 1.0 / 2.2);
return grayLevel;
}