Click here to Skip to main content
15,888,062 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi everyone, I've tried to write code about draw line on picture, but I don't know how can I do.
1. Open picture
2. click many points on picture. For example, point 1 point2 point3 , the point will appear.
3. when you keyC from keyboard. Line will appear like point 1 ---> point 2 ---> point 3 ---> point 1 sth like that

Ps. I use Cimg.h and I don't know how to do, I've tried to read many code but don't understand at all. So I know you can help me, thank you :)

C++
#include <cimg.h>
#include<math.h>
using namespace cimg_library;
int main(){

    CImg<unsigned char> img("picture_trial/lion.jpg");
    CImgDisplay img2(img,"Display Image");
    const unsigned char color[3] = {0,0,255};
    while(!img2.is_closed())
    {
        if(img2.key() == cimg::keyESC)
            img2.close();
        if(img2.button()&1)
        {
            img.draw_line(img2.width()/2,img2.height()/2,img2.mouse_x(),img2.mouse_y(),color,1);
            img2.display(img);
        }
    }


}
Posted
Updated 10-Apr-15 20:44pm
v2

1 solution

As I understand your code you must see the line drawing. If you want to save the line in the picture you must call the save_jpg function on the CImg.
 
Share this answer
 

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