运行一下以下代码
$img = imagecreatetruecolor(600, 600);
$white = imagecolorallocate($img, 255, 255, 255);
imagedashedline($img, 20, 20, 500, 20, $white);
imagedashedline($img, 20, 20, 20, 500, $white);
header("content-type:image/jpeg");
imagejpeg($img);
imagedestroy($img);
你会发现垂直的虚线没问题,但水平虚线就不显示。有谁知道为什么?

解决方案 »

  1.   

    另使用
    $red = imagecolorallocate($img, 255, 0, 0);
    $style = array($red, $red, $red, $red, $red, $white, $white, $white, $white, $white);
    imagesetstyle($img, $style);
    imageline($img, 20, 20, 20, 500, IMG_COLOR_STYLED);
    也是一样。
      

  2.   

    $img = imagecreatetruecolor(600, 600);
    $white = imagecolorallocate($img, 255, 255, 255);
    $red = imagecolorallocate($img, 255, 0, 0);$style = array($red, $red, $red, $red, $red, $white, $white, $white, $white, $white);
    imagesetstyle($img, $style);
    imageline($img, 20, 20, 500, 20, IMG_COLOR_STYLED);header("content-type:image/jpeg");
    imagejpeg($img);
    imagedestroy($img);
      

  3.   

    The bug reported by 'michi at marel dot at' also exists in PHP version 5.1.1. This functions just works with vertical lines! 5.1.1版本发现的BUG,反对使用本函数。应该用 imagesetstyle() 和 imageline() 的组合替代之
      

  4.   

    This functions just works with vertical lines!该函数只能画垂直线!
      

  5.   

    这个代码单独拿出确可以画出垂直虚线,但是组合到代码复杂些的图形中就不行了,imageline($this->m_hImageResource, 40, 20, 40, 500, IMG_COLOR_STYLED);该imageline($this->m_hImageResource, 40, 20, 40, 500, 0);可以看到黑色的直线,改回imageline($this->m_hImageResource, 40, 20, 40, 500, IMG_COLOR_STYLED);就不行了。看来还是放弃虚线吧。