0

I have done smallest enclosing circle problem.

I want to know if I have n points and circle in form of radius and center than can I print all these things on graph.

Printing means "Can I make a Image"

If someone knows please tell me what things I have to learn .

user69910
  • 971
  • 2
  • 9
  • 14
  • Do you want to write an image file on the disk (eg. `.png` or `.jpg`) or to display graphics on the screen? – syam May 22 '13 at 08:08
  • 2
    YES! There are many ways to create images using C++. And you can also [create C++ out of images](http://stackoverflow.com/questions/5588649/how-did-this-person-code-hello-world-with-microsoft-paint), you know. – Mark Garcia May 22 '13 at 08:08
  • Please read the [faq]. You're not having much success getting answers to your questions. You need to formulate them far better. Show what you've tried, or found. Explain what your problem is (your problem this time seems to be that you haven't looked for plotting libraries, which isn't a problem I can help you with, you need to get on and do it). – Peter Wood May 22 '13 at 08:15

4 Answers4

1

By itself, neither C++ nor its standard library include any functions for dealing with images. To work with images (loading, saving, etc), you need to either do the hard work yourself, or link with a third-party library.

The simplest way is to dump your image to disk in Netpbm format. This format is so simple that you can get away with writing things yourself. There's a library to do that, too. The format does not use any compression, so you will end up with images that are larger than you may expect, but if you're just doing exploratory coding, then it may be good enough.

Other libraries include libjpeg and libpng. Both of these libraries are format-specific (they only work for a certain image format). Libraries that are not format-specific include OpenCV, which actually uses libjpeg and libpng internally.

EDIT

After reading your question, I've realized that your problem isn't just saving the image, it's actually creating it (as well as saving it). The easiest way to "create" an image is to allocate a byte array. Logically, the array is two dimensional: typically, the first dimension corresponds to the height of the image, and the second dimension corresponds to the width. Once you've created your image, you can "draw" on it by setting the values within the array. For example, to draw a line, you enumerate the (x, y) positions on the line, and set the value of the pixel at each position to the desired value.

Finally, when you want to output the image, refer to the first part of my answer.

mpenkov
  • 21,621
  • 10
  • 84
  • 126
  • I have heard about openCV . Can I create points and circle in openCV??. and please suggest me library(out of you have mentioned) that is useful to learn. – user69910 May 22 '13 at 09:01
  • Yes, OpenCV has drawing functions for elementary shapes, including circles (http://docs.opencv.org/modules/core/doc/drawing_functions.html#circle). I suggest you learn that library -- it's very useful and convenient. – mpenkov May 22 '13 at 09:08
0

To create images you will have to deal with external libraries and such... do you really need that?

It seems you are dealing with a "scientific app", i'd suggest to output a .txt file and use gnuplot to draw your images

Exceptyon
  • 1,584
  • 16
  • 23
  • netpbm requires almost the same effort as output to txt, and produces actual images that are compatible with most image viewers – mpenkov May 22 '13 at 08:18
  • 1
    @misha: you are right, it wouldn't be that hard. But: a few times i had to "create images" of atom positions. Those positions will be double[], to draw them into a bitmap you'll have to scale the scene and round them to int (pixel coords). Calculate scale is non-trivial (10^n atoms on the same pixel and one at the other edge of the pic = useless image), and once an image is calculated you can't "zoom it". ...for these apps I usually end up writing a gnuplot script so that i can see and analyze the results with an actual tool, instead of MsPaint :) – Exceptyon May 22 '13 at 08:30
  • output coordinates and then use octave?? – user69910 May 22 '13 at 08:55
0

You can use either cimg or opengl. For the latter check out this question OpenGL - draw pixels to screen?

Community
  • 1
  • 1
Potney Switters
  • 2,902
  • 4
  • 33
  • 51
0

You may like to use libpng and optionally also png++.

axon
  • 1,190
  • 6
  • 16