How to generate a captcha image with libcapt.
You can find a helloworld sample at "examples" fold
- load libcapt font with libCapt::FontFile
libCapt::FontFile fontFile;
fontFile.loadFromDataStream(fontStream, fontStreamSize);- generate captcha question with libCapt::Generator
libCapt::Question question;
libCapt::Generator generator(&fontFile);
generator.generateQuestion(question);- libCapt::Question include a captcha image with four random character.
unsigned char imageBuf[IMAGE_BUF_LENGTH]; //image data with rle compressed
- also, libCapt::Question include four answer with one correct.
unsigned short wAnswer0[ANSWER_LENGTH]; //unicode character
unsigned short wAnswer1[ANSWER_LENGTH];
unsigned short wAnswer2[ANSWER_LENGTH];
unsigned short wAnswer3[ANSWER_LENGTH];
int nCorretAnswer;- you can transfer imageBuf to client now
- decompress imageBuf with libCapt::rleDecompress at client
unsigned char bitBuf[IMAGE_BUF_LENGTH];
if(question.isCompressed())
{
rleDecompress(question.imageBuf, question.getSize(), IMAGE_WIDTH, IMAGE_HEIGHT, bitBuf, bufSize);
}
else
{
memcpy(bitBuf, question.imageBuf, IMAGE_BUF_LENGTH);
}- now, you can show image on device with imageBuf data(4bit format)
the constant "ANSWER_LENGTH" in No.4 step should be "ANASWER_LENGTH". or captGenerator.h should be changed as chagne "ANASWER_LENGTH" to "ANSWER_LENGTH"