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
#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.