draw62188 2015-07-24 11:15
浏览 200

PHP ImageColorAllocate返回值

I have the following code to set 2 colours:

$_colours = array(
    0 => array(
        'r' => 255,
        'g' => 0,
        'b' => 0
    ),
    1 => array(
        'r' => 0,
        'g' => 255,
        'b' => 0
    )
);

$col[0] = ImageColorAllocate($base_image,$_colours[0]['r'],$_colours[0]['g'],$_colours[0]['b']);
$col[1] = ImageColorAllocate($base_image,$_colours[1]['r'],$_colours[1]['g'],$_colours[1]['b']);

However, $col[0] and $col[1] return 0 and 1 respectively, and instead of being red and green, I actually get black and white. I'm under the impression these should return a number for that colour, rather than 1/0.

Furthermore, I can change these r/g/b values to almost anything else I still get the same return values.

Is there something else I need to do?

  • 写回答

1条回答 默认 最新

  • douningchang3610 2015-07-24 11:31
    关注

    imageColorAllocate returns a color identifier or FALSE if the allocation failed.

    What your array holds should be resources (identifiers), not colors as such.

    try:

    imagesetpixel($base_image,5,5,$col[0]);
    

    that should use the identifier to draw a pixel with your color.

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘