My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
PageName  
How to generate a captcha image with libcapt.
Updated Nov 5, 2010 by thejinc...@gmail.com

How to generate a captcha image with libcapt.

You can find a helloworld sample at "examples" fold
  1. load libcapt font with libCapt::FontFile
  2.       libCapt::FontFile fontFile;
          fontFile.loadFromDataStream(fontStream, fontStreamSize);
  3. generate captcha question with libCapt::Generator
  4.       libCapt::Question question;
          libCapt::Generator generator(&fontFile);
          generator.generateQuestion(question);
  5. libCapt::Question include a captcha image with four random character.
  6.       unsigned char imageBuf[IMAGE_BUF_LENGTH];  //image data with rle compressed
  7. also, libCapt::Question include four answer with one correct.
  8.       unsigned short wAnswer0[ANSWER_LENGTH];  //unicode character
          unsigned short wAnswer1[ANSWER_LENGTH];
          unsigned short wAnswer2[ANSWER_LENGTH];
          unsigned short wAnswer3[ANSWER_LENGTH];
          int nCorretAnswer;
  9. you can transfer imageBuf to client now
  10. decompress imageBuf with libCapt::rleDecompress at client
  11.        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);
           }
  12. now, you can show image on device with imageBuf data(4bit format)
Comment by cybloc...@gmail.com, Jul 12, 2012

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"

Powered by Google Project Hosting