开发者

Interesting problem notices in php imagecolorallocate. I am stuck and need valuable suggestions

Here are two pieces of code. First I try to allocate an colour to the image and save the image

<?php $im = @imagecreatetruecolor(200, 200)
  or die('Cannot Initialize new GD image stream'); 
  $color = imagecolorallocate($im, 143, 198, 269);
  {
    for ($j=0; $j<200; $j++)
    {       

    imagesetpixel ($im, $i, $j, $color);

    }

     }              

     $filename = 'test.png';

     imagepng($im, $filename);

      ?>

In second piece I read the saved image and print the allocated color开发者_运维问答.

    <?php

    $filename = 'test.png';

    $im = imagecreatefrompng($filename);

    $rgb = imagecolorat($im, 1, 1);
    $r = ($rgb >> 16) & 0xFF;
    $g = ($rgb >> 8) & 0xFF;
    $b = $rgb & 0xFF;

    echo "allocated color: r =".$r."g =".$g."b =".$b;


    ?>

It prints : allocated color: r =143 g =199 b =13 Hence the allocated color is completely different from the one which I wanted. Now How do I deal with this. Any suggestions please.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜