예, 다각형 채우기 패턴은 먼저 단색으로 다각형을 그린 다음 사전로드 된 흑백 패턴 이미지와 함께 & = 연산자를 사용하여 얻을 수 있습니다.
// preload several pattern images (black and white versions of the desired fill patterns)
CImg<unsigned char> *fillPatternImages[ NumFillPatterns ] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
fillPatternImages[ 0 ] = new CImg<unsigned char>("256x256_bw_dotted_fill.png");
... etc. for all patterns you want to use
// create an empty image
CImg<unsigned char> image(256, 256, 1, 4, 0);
// draw the polygon (or in the case of my code, any number of polygons) on the image in a solid color
if (nShapeType == SHPT_POLYGON && fillPattern != FILL_PATTERN_NONE)
{
for(int i = 0 ; i < nShapeCount ; i++)
{
SHPObject *psShape;
psShape = SHPReadObject(hSHP, panHits[ i ]);
for (int part = 0 ; part < psShape->nParts ; part++)
{
int numPoints;
if (part < (psShape->nParts - 1))
{
numPoints = psShape->panPartStart[ part + 1 ] - psShape->panPartStart[ part ];
}
else
{
numPoints = psShape->nVertices - psShape->panPartStart[ part ];
}
CImg<int> pointImage(numPoints, 2, 1, 1, 0);
int s = psShape->panPartStart[ part ];
for (int p = 0 ; p < numPoints ; p++)
{
int screenX;
int screenY;
GetTileXYFromMercatorLonLat((float)psShape->padfX[ s + p ], (float)psShape->padfY[ s + p ], x, y, z, &screenX, &screenY);
pointImage(p, 0) = screenX;
pointImage(p, 1) = screenY;
}
image.draw_polygon(pointImage, fillColor);
}
SHPDestroyObject(psShape);
}
}
// to achieve a non-solid pattern, & the image with a pre-loaded pattern image
if (fillPattern > -1)
{
image &= *fillPatternImages[ fillPattern ];
}