i want to get RGB code for each pixel. As example i took pixel(0,0) (corner left). I load JPEG image and then store in Bitmap object in Java. For experiment i attach the image for example :
I take RGB with PHP and Java. Here the code :
Java (rgbImage is Bitmap object which loaded from JPEG file) :
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/>");
}
}
}
And the result both of them are :
JAVA : I/System.out: red : 91.0 green : 91.0 blue : 101.0
PHP : r : 93 , g : 91, b : 102
The Main Question is :
Why with the same image, two methods above can give different result?