填充几何图形
2016-08-03 19:45
288 查看
使用GD2函数不仅可以绘制线条图形,而且可以绘制填充图形,如填充圆形,填充矩形等。下面对GD2中常用的填充图形的绘制方法进行介绍。
bool imagefill( resource image, int x, int y, int color )
imagefill()函数在image图像的坐标( x, y ) (图像的左上角为(0,0))处用color颜色执行区域填充(即与(x,y)点颜色相同切相邻的点都会被填充)。
bool imagefilledarc ( resource
imagefilledarc() 在
0, 0)画一椭圆弧。成功时返回
bool imagefilledellipse ( resource
imagefilledellipse() 在
0, 0)为中心画一个椭圆。
或者在失败时返回
bool imagefilledrectangle( resource image, int x1, int y1, int x2, int y2, int color )
该函数在image图像中绘制一个用color颜色填充了的矩形, 其左上角坐标为(x1, y1),右下角的坐标为(x2, y2)。(0,0)为图像的左上角。
例如:应用如上函数,绘制填充圆形和填充正方形,代码如下
<?php
header("Content-type: image/png");//将图像输出到浏览器
$img = imagecreate(400, 200);//创建一个400X200的画布
$bg = imagecolorallocate($img, 0, 0, 255);//设置背景颜色
$white = imagecolorallocate($img, 255, 255 ,255);//设置填充颜色
imagefilledellipse($img, 100, 100, 150, 150, $white);//绘制填充圆形
imagefilledrectangle($img, 200, 50, 300, 150, $white);//绘制填充正方形
imagepng($img);//以png格式输出图像
imagedestroy($img);//释放资源
运行结果如下所示
bool imagefill( resource image, int x, int y, int color )
imagefill()函数在image图像的坐标( x, y ) (图像的左上角为(0,0))处用color颜色执行区域填充(即与(x,y)点颜色相同切相邻的点都会被填充)。
bool imagefilledarc ( resource
image, int
cx, int
cy, int
w, int
h, int
s, int
e, int
color, int s
tyle)
imagefilledarc() 在
image所代表的图像中以
cx,
cy(图像左上角为
0, 0)画一椭圆弧。成功时返回
TRUE, 或者在失败时返回
FALSE.
w和
h分别指定了椭圆的宽和高,
s和
e参数以角度指定了起始和结束点。
style可以是下列值按位或(OR)后的值:
IMG_ARC_PIE
IMG_ARC_CHORD
IMG_ARC_NOFILL
IMG_ARC_EDGED
IMG_ARC_PIE和
IMG_ARC_CHORD是互斥的;
IMG_ARC_CHORD只是用直线连接了起始和结束点,
IMG_ARC_PIE则产生圆形边界(如果两个都用,
IMG_ARC_CHORD生效)。
IMG_ARC_NOFILL指明弧或弦只有轮廓,不填充。
IMG_ARC_EDGED指明用直线将起始和结束点与中心点相连,和
IMG_ARC_NOFILL一起使用是画饼状图轮廓的好方法(而不用填充)。
bool imagefilledellipse ( resource
image, int
cx, int
cy, int
w, int
h, int
color)
imagefilledellipse() 在
image所代表的图像中以
cx,
cy(图像左上角为
0, 0)为中心画一个椭圆。
w和
h分别指定了椭圆的宽和高。椭圆用
color颜色填充。成功时返回
TRUE,
或者在失败时返回
FALSE.
bool imagefilledrectangle( resource image, int x1, int y1, int x2, int y2, int color )
该函数在image图像中绘制一个用color颜色填充了的矩形, 其左上角坐标为(x1, y1),右下角的坐标为(x2, y2)。(0,0)为图像的左上角。
例如:应用如上函数,绘制填充圆形和填充正方形,代码如下
<?php
header("Content-type: image/png");//将图像输出到浏览器
$img = imagecreate(400, 200);//创建一个400X200的画布
$bg = imagecolorallocate($img, 0, 0, 255);//设置背景颜色
$white = imagecolorallocate($img, 255, 255 ,255);//设置填充颜色
imagefilledellipse($img, 100, 100, 150, 150, $white);//绘制填充圆形
imagefilledrectangle($img, 200, 50, 300, 150, $white);//绘制填充正方形
imagepng($img);//以png格式输出图像
imagedestroy($img);//释放资源
运行结果如下所示
相关文章推荐
- OpenCV与EmguCV中的漫水填充
- CodeFirst 建表 + 填充数据 流程
- iOS 图片填充 UIImageView
- 禁掉浏览器自动填充
- chrome浏览器当表单自动填充时如何去除浏览器自动添加的默认样式
- Android短信验证码自动填充功能
- ruby数组填充方法
- java实现输出排版问题,自动填充
- Android自定义标题栏填充不满的解决方法
- Toolbar.inflateMenu填充无效
- 布局填充的另一种方法
- 计算机图形学(三)_图元的属性_12_ 曲线边界区域的扫描线填充
- prepareStatement进行增删改查---填充占位符(防止sql注入)
- web前端-CSS Padding(填充)-014
- 网页填充内容
- 带着实例继续学习(4):下拉框数据填充、组件生命周期、动态绑定事件
- 375_改变图片的填充颜色
- HPU-1029-QAQ的填充方案【组合数】【卡特兰数】
- 迁移和填充
- 前端文本框自动填充