Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从PHP GD中已分配的颜色中获取rgb颜色_Php_Colors_Gd_Rgb - Fatal编程技术网

如何从PHP GD中已分配的颜色中获取rgb颜色

如何从PHP GD中已分配的颜色中获取rgb颜色,php,colors,gd,rgb,Php,Colors,Gd,Rgb,如何从分配的颜色中获取颜色 类似于 $col = imagecolorallocate($im, 255, 50, 5); //A fake function - rgbfromallocate (that I wish I knew) $rgb = rgbfromallocate($col); print $rgb['r'];//255 print $rgb['g'];//50 print $rgb['b'];//5 也许这就是你要找的 例如: // $img is an image $c

如何从分配的颜色中获取颜色 类似于

$col = imagecolorallocate($im, 255, 50, 5);
//A fake function - rgbfromallocate (that I wish I knew)

$rgb = rgbfromallocate($col);
print $rgb['r'];//255
print $rgb['g'];//50
print $rgb['b'];//5
也许这就是你要找的

例如:

// $img is an image
$color = imagecolorallocate($img, 255, 50, 5);

$rgb = imagecolorsforindex($img, $color);
print $rgb['red']; // 255
print $rgb['green']; // 50
print $rgb['blue']; // 5
print $rgb['alpha']; // 0, but if the image uses the alpha channel,
// this would have a value of up to 127, which is fully transparent
也许这就是你要找的

例如:

// $img is an image
$color = imagecolorallocate($img, 255, 50, 5);

$rgb = imagecolorsforindex($img, $color);
print $rgb['red']; // 255
print $rgb['green']; // 50
print $rgb['blue']; // 5
print $rgb['alpha']; // 0, but if the image uses the alpha channel,
// this would have a value of up to 127, which is fully transparent

如果只打印r$col会发生什么?尽管未经测试,但页面上的第一条注释表明该函数实际上只是返回一个由4对组成的十六进制值-alpha、红色、绿色、蓝色-也许它的存储非常简单?Stephen:$col是表示图像调色板中颜色的数字。如果像许多图像一样,此图像具有RGB调色板,那么您所说的就是这种情况。但是,如果图像使用其他调色板,则必须使用
imagecolorsforindex()
获取颜色的RGB值。如果只打印$col会发生什么情况?尽管未经测试,但页面上的第一条注释表明该函数实际上只是返回一个由4对组成的十六进制值-alpha、红色、绿色、蓝色-也许它的存储非常简单?Stephen:$col是表示图像调色板中颜色的数字。如果像许多图像一样,此图像具有RGB调色板,那么您所说的就是这种情况。但是,如果图像使用其他调色板,则必须使用
imagecolorsforindex()
来获取颜色的RGB值。工作完美,我原以为该函数仅适用于imagecolorat,但事实正是如此。工作完美,我原以为该函数仅适用于imagecolorat,但事实正是如此。