I am writing a class in C++14 that gives the ability to read, write and edit bmp images. I must not use any third party library and do it all alone. I manage to read, write and draw shapes on the image, but I couldn't find a way to draw text without a library. Any suggestions?
Related
Is there a way to output a text at some (x,y) position having a certain "size", such as a numeral '1'? For example in gnuplot, we can use
plot ... using x:y:size w labels center...
Is there something similar which I can use with the libjpeg library?
No
libJPEG is only a loading/saving library. It allows the conversion of JPEG to other more workable formats and back. You will need some sort of image processing library (e.g. OpenCV) or high-level graphics library (e.g. DirectX, SFML). There are a lot of image libraries that implement writing of text on a bitmap. libJPEG will allow you to decode into a bitmap format in memory and from there you can work with pretty much any other library that has functions that write text onto a bitmap.
Personally, I would just use SFML since you can load a JPG file (or any image format for that matter), set that texture as a render target, render text, and then get the texture for that and save it back. But any high level graphics library should do the trick...like listed above.
Via GDI/GDI+ get the text pixels or glyph, how to convert to 3d mesh? Does any exists library or source code can be used?
PS: I know D3DXCreateText, but Im using opengl...
If you works on OpenGL, you can try FTGL, it allows you to generate different polygon meshes from fonts, including extrudes meshes as well as render them:
http://ftgl.sourceforge.net/docs/html/ftgl-tutorial.html
but I am not sure how portable is this library specially for OpenGL ES...
Using GDI is definitely not among the best ways to go if you need to obtain glyphs for the text, you could use FreeType library instead (http://www.freetype.org), which is open-source and portable. It can produce both bitmaps and vectorized representation for the glyphs. You will have to initialize single instance of class FT_Library in your program that is later used to work with multiple fonts. After loading font form file (TrueType, OpenType, PostScript and some other formats) you'll be able to obtain geometrical parameters of specific characters and use it appropriately to create texture or build primitives using your preferred rendering API, OpenGL let it be.
I'm just curious if there is a way to use OpenGL to write pixel data to an external JPEG/PNG/some other image file type (and also create an image to write the data to if one does not already exist). I couldn't really find anything on the subject. My program doesn't really make use of openGL at all otherwise, I just need something that can write out images.
Every image "put into" or "taken from" OpenGL is in a rather raw pixel format. OpenGL does neither have functionality for file I/O nor for handling of sophisticated image formats like e.g. BMP, JPEG or PNG, as that is completely out of its scope. So you will have to look for a different library to manage that and if this was the only reason you considered OpenGL, then you don't need it at all.
A very simple and easy to use one (and with an interface similar to OpenGL) would be DevIL. But many other larger frameworks for more complex tasks, like Qt (GUI and OS) or OpenCV (image processing) have functionality for image loading and saving. And last but not least many of the individual formats, like JPEG or PNG usually also have small official open-source libraries for handling their respective files.
How can I "draw"\"merge" a png top of another png (background) using libpng, while keeping the alpha section of the png being drawn on top of the backhround png. There does not seem to be any tutorials or anything mentioned in the documentation about it.
libpng is a library for loading images stored in the PNG file format. It is not a library for blitting images, compositing images, or anything of that nature. libpng's basic job is to take a file or memory image and turn it into an array of color values. What you're talking about is very much out of scope for libpng.
If you want to do this, you will have to do the image composition yourself manually. Or use a library that can do image composition (cairo, etc).
Sometimes it is beneficial to actually display some information overlaid on the video sequence when doing video processing with OpenCV. Is it possible to do this? How might that be done?
There is a function cv::putText which can be used to draw text into an image. So just grab the image from the video and draw the text on top of it before showing it. There should also be a similar function in the OpenCV C-API, but since you tagged it C++ I assume you use the C++ API, anyway.
EDIT: Of course this function modifies the image, which then also contains the drawn text. So if you still need the original image for further processing, you should use cv::displayOverlay. This might actually be a better solution than cv::putText, since it is a bit easier to use and is intended exactly for showing some small information over an image in a highgui window.