PHPでimagefilledpolygon()関数を使用して塗りつぶされたポリゴンを描画するにはどうすればよいですか?
imagefilledpolygon() 塗りつぶされたポリゴンを描画するために使用される組み込みのPHP関数です。
構文
bool imagefilledpolygon($image, $points, $num_points, $color)
パラメータ
imagefilledpolygon() $ image、$ points、$ num_points、$colorの4つの異なるパラメータを取ります。
-
$ image − imagecreatetruecolor()関数を使用して、指定されたサイズで空白の画像を作成します。
-
$ポイント −ポリゴンの連続する頂点を保持します。
-
$ num_points −ポリゴン内の頂点の総数が含まれます。ポリゴンを作成するには、ポイント/頂点の総数が3つ以上である必要があります。
-
$ color − imagecolorallocate()関数を使用して塗りつぶされた色識別子が含まれます。
戻り値
成功するとTrueを返し、失敗するとFalseを返します。
例1
<?php
// set up array of points for a polygon
$values = array(
40, 50, // Point 1 (x, y)
20, 240, // Point 2 (x, y)
60, 60, // Point 3 (x, y)
240, 20, // Point 4 (x, y)
50, 40, // Point 5 (x, y)
10, 10 // Point 6 (x, y)
);
// create the image using imagecreatetruecolor function
$img = imagecreatetruecolor(700, 350);
// allocated the blue and gray colors
$bg = imagecolorallocate($img, 122, 122, 122);
$blue = imagecolorallocate($img, 0, 0, 255);
// filled the background
imagefilledrectangle($img, 0, 0, 350, 350, $bg);
// draw a polygon
imagefilledpolygon($img, $values, 6, $blue);
// flush image
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?> 出力
例2
<?php
// Set the vertices of the polygon
$values = array(
150, 50, // Point 1 (x, y)
55, 119, // Point 2 (x, y)
91, 231, // Point 3 (x, y)
209, 231, // Point 4 (x, y)
245, 119 // Point 5 (x, y)
);
// It creates the size of the image or blank image.
$img = imagecreatetruecolor(700, 350);
// Set the gray background image color
$bg = imagecolorallocate($img, 122, 122, 122);
// Set the red image color
$red = imagecolorallocate($img, 255, 0, 0);
// fill the background
imagefilledrectangle($img, 0, 0, 350, 350, $bg);
// Draw the polygon image
imagefilledpolygon($img, $values, 5, $red);
// Output of the image.
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?> 出力
-
Javaを使用してOpenCVで塗りつぶされたポリゴンを描画するにはどうすればよいですか?
Java OpenCVライブラリのorg.opencv.imgprocパッケージには、Imgprocという名前のクラスが含まれています。塗りつぶされたポリゴンを描画するには、 fillPoly()を呼び出す必要があります。 このクラスのメソッド。このメソッドは、次のパラメーターを受け入れます- ポリゴンが描画される画像を表すマットオブジェクト。 タイプMatOfPointのオブジェクトを保持するリストオブジェクト。 ポリゴンの色を表すScalarオブジェクト。 線種を表す整数。 例 import java.util.ArrayList; import java.ut
-
OpenCV関数fillPoly()を使用して塗りつぶされたポリゴンを描画します
このプログラムでは、opencv関数fillPoly()を使用して塗りつぶされたポリゴンを描画します。この関数は、画像とポリゴンの端点を取り込みます。 アルゴリズム Step 1: Import cv2 and numpy. Step 2: Define the endpoints. Step 3: Define the image using zeros. Step 4: Draw the polygon using the fillpoly() function. Step 5: Display the output. サンプルコード import cv2 import numpy as