Ich möchte RGB-Code für jedes Pixel erhalten. Als Beispiel habe ich Pixel (0,0) genommen (Ecke links). Ich lade JPEG-Bild und dann in Bitmap-Objekt in Java speichern. Für Experiment anhängen ich das Bild zum Beispiel:Get RGB in Java und PHP haben unterschiedliche Ergebnisse
Ich nehme RGB mit PHP und Java. Hier ist der Code:
Java (rgbImage ist Bitmap-Objekt, das von JPEG-Datei geladen):
int width = rgbImage.getWidth();
int height = rgbImage.getHeight();
for (int x = 0; x < rgbImage.getWidth(); x++){
for (int y = 0; y < rgbImage.getHeight(); y++) {
int pixel = rgbImage.getPixel(x, y);
double red = Color.red(pixel);
double green = Color.green(pixel);
double blue = Color.blue(pixel);
if(x == 0 && y == 0){
System.out.println("red : "+red+" green : "+green+" blue : "+blue);
}
PHP:
$rgbImage = imagecreatefromjpeg("$path");
$width = imagesx($rgbImage);
$height = imagesy($rgbImage);
for($x = 0 ; $x < $width ; $x++){
for($y = 0 ; $y < $height ; $y++){
$rgb = imagecolorat($rgbImage, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
if($x == 0 && $y == 0){
echo("r : $r , g : $g, b : $b <br/>");
}
}
}
Und das Ergebnis sowohl von ihnen sind:
JAVA: I/System.out: rot: 9 1,0 grün: 91,0 blau: 101,0
PHP: R: 93 g: 91, b: 102
Die Hauptfrage ist:
Warum mit dem gleichen Bild zwei Verfahren können oben geben anderes Ergebnis?
Da Sie ein JPEG haben, könnte etwas darüber sein, wie das API die Datei liest, dies ist keine Bitmap, also werden die Werte nicht für jedes Pixel geschrieben, sondern ausgewertet. Lies dies [post] (http://stackoverflow.com/questions/17893814/java-create-and-read-rgb-pixel-value-different?rq=1) über etwas Äquivalent – AxelH
@axelh: ich vergesse es zu erzählen. Ich lade ein JPEG-Bild und speichere es im Bitmap-Objekt. – Michael
@axelh: Du meinst die Qualität von JPEG bringt auf Unkomprimiert (Bitmap) zurück? – Michael