Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
I've tried to write code about draw line on picture, but I don't know how can I start.
1. Open picture
2. click many points on picture. For example, point 1 to point2 to point3 to bla vla bla , the line between point will appear.

3. when you press keyC from keyboard. The line between point 1 to the last point will appear

Here's my code

C++
#include <cimg.h>
   #include<math.h>
   using namespace cimg_library;
   int main()
   {
       int n=1;
       int a,b,c,d;

       CImg<unsigned char> img("stupid.jpg");
       CImgDisplay img2(img,"Display Image");
       const unsigned char color[]  = {255,128,128},
                           color1[] = {128,255,255};
       while(!img2.is_closed())
       {
           if(img2.key() == cimg::keyESC)
               img2.close();
           if(img2.button()&1)
           {
               if(n==1){
                   a=img2.mouse_x();
                   b=img2.mouse_y();
                   img.draw_line(a,b,img2.mouse_x(),img2.mouse_y(),color,1);
                   img2.display(img);
                   c=img2.mouse_x();
                   d=img2.mouse_y();
                   n++;
                   }
               else{
                   img.draw_line(c,d,img2.mouse_x(),img2.mouse_y(),color,1);
                   img2.display(img);
                   c=img2.mouse_x();
                   d=img2.mouse_y();
                   }
           }
       }
       if(img2.key()==cimg::keyC)
               {
                   img.draw_line(c,d,a,b,color,1);
                   img2.display(img);
                   n=1;
               }
   return 0;
   }


I use Cimg library then I don't know when I press keyC on keyboard, the line don't appear.
Posted
Updated 20-Apr-15 23:13pm
v2
Comments
Sergey Alexandrovich Kryukov 21-Apr-15 10:23am    
You called display object "img2", very confusing. You should never give such names, with those "1", "2", etc.
Look at the first example of the manual and try to execute it first...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900