Saving image as JPG -library? - c++

I'd like to find a JPEG-writing library that can be statically linked (so there are no DLL dependencies). No JPEG-reading ability is required.
Edit: I got LibGD working, but it had one problem described here:
LibGD library is not working: crash when saving image

libjpeg is the most popular library for saving jpegs, but it can be a bit of a pain to use.
Edit, here is a simple example of how to use it. Look for the function juce_writeJPEGImageToStream.

Have you looked at LibGD? I can't seem to find the license, but neither did you specify a requirement.

If you're running your application on Windows then you should use the standard, built-in "GDI+" library that Microsoft provides. Every computer running XP or later has this library.
GDI+ is intended to supersede GDI, which is what you're probably already using whether you know it or not, but it can co-exist with GDI calls provided you flush the buffers when switching between the two. See:
http://www.cpjj.net/Miscellaneous/CreateJPEGFromDC.htm
(Hans Passant - you should have written your comment as an answer).

Related

How to get a list of available resolutions for every camera on Windows C++

I have multiple cameras in my Windows 11 system and I am wondering how to get all avaiable resolutions for them. I am not intending to make a video capture, but I am willing to just get these properties.
Also, I don't care which API to use, be it DirectShow or MMF (Microsoft Media Foundation).
I haven't used any of these before either.
I have found multiple resources doing that in C# (as in here), but similar suggested answers for C++ are hard to understand - some code is given, but what libraries and 'includes' used is not given (as in here)
I have also checked DirectShow samples in hope something would be there, but I didn't find anything.
So, I checked MMF as well (1, 2, 3) and docs, but all posts seem pretty outdated and no full code is given showing how to use certain functions alongside proper 'includes', as trying the code gives me unresolved symbols.
So I am kind of stuck at the moment, I can't find a solution to this.
I would appreciate any help.
Also, I don't care which API to use, be it DirectShow or MMF (Microsoft Media Foundation). I haven't used any of these before either.
You generally do care because the data might be different.
With Media Foundation, see How to Set the Video Capture Format
Call IMFMediaTypeHandler::GetMediaTypeCount to get the number of supported formats.
You might also want to have a look at Tanta:
Windows Media Foundation Sample Projects and sample code there.
With DirectShow, see Webcamera supported video formats in addition to links you found; you will have to sort out includes and libraries through, among SDK samples AMCap does some one this and can be built from source without additional external libraries, from original code or from this fork adopted to most recent VS.

C++: Writing images to video file independent of installed codecs

I'm trying to save a series of images (16 bit grayscale pgm) as video. The video has to be compressed. My program has to be independent of the codecs installed in the system.
My initial idea was to use OpenCV for this, unfortunately it depends on codecs installed in the system (unless I'm missing something).
I feel like there should be a way to compile an encoder (H264 or similar would be perfect) into the program or redistribute it as a dll with my program. I just can't find any good up to date guidance/examples.
I've been swimming in the deep vast ocean of AV encoding for a couple of days and would really appreciate it if someone could point me to a right direction.
Thanks.
As Ben suggests, it would be a good idea to use an established library in your code.
FFMPEG is probably the most used at the moment - it can be used on the command line, with a 'wrapper' program or the libraries it is built with can be used directly.
I think the last case sounds like the one you want - you can find documentation here:
https://trac.ffmpeg.org/wiki/Using%20libav*
Note the comment about disambiguation at the start - this is important to understand as the project lib and the library (which is what you want) are different things.
and there is some notes in this answer on how to build it into a program:
FFMpeg sample program

Equivalent for TzSpecificLocalTimeToSystemTime() on win2k?

One of our developers used this call:
TzSpecificLocalTimeToSystemTime() but unfortunately we cannot keep it as the code must work on Win2K as well.
What alternatives are there for similar functionality?
There is no equivalent, not even with WINE. It relies on timezone info stored in the registry, retrieved with GetTimeZoneInformation(). Note how the WINE code ends up in find_reg_tz_info(). That info is just missing in Win2k.
You'd have to create your own timezones table.
If you're open to including LGPL code in your project, you could grab that function's implementation from Wine.

How can I read/load images in C++?

i am more a java developer and there is a standard way of reading images :
BufferedImage img = null;
try {
img = ImageIO.read(new File("strawberry.png"));
} catch (IOException e) {
}
but what is the c++ way of loading images? I want to load all images in a specific directory into an array or so.
Personally, I prefer the ImageMagick library.
There are many available graphics processing libraries, and there is not a single choice that stands out as clearly superior to the others. My advice is to make a short list of 3 or 4, take a look at the documentation for each, and try to write a simple half-page program with each. Use whichever one you personally find easiest to use.
There is no standard "way" in C++ to load images or files of any other sort. That feature is provided by (usually third-party) libraries.
On Windows, you can use the GDI or DirectX APIs to load images to memory.
You can also use any of many different libraries. Some that come to mind:
SDL-Image
ImageMagick
Qt's QImageReader
wxWidgets
cImg (Which will try to read files if the appropriate filetype-specific library is available.)
Boost.GIL (Which, apparently, has support for JPEG, PNG, and TIFF files.)
There are many, many others to look at, and some may be more appropriate than others depending on what you're trying to do.
For example, if you're only going to be working with JPEG files, then you'll want to use libIJG. Or if you'll only be using PNG, you might find libPNG or cairo to be more appropriate.
The library you will want to use to load images will depend on what you intend to do with it. If you are using a framework such as QT or wxWidgets, it will provide image loading routines.
Another possibility is to use the the SDL Image library, and to work on SDL surfaces, which will allow you to work down to the pixel level if you need.
Take a look at DevIL
Qt has good support for images, and is free and cross-platform.
Check out the qimage class
I would say that the closest you'll get to a standard way of doing this is with the Boost/Adobe Generic Image Library.

C++ libraries to manipulate images

Do you know any open source/free software C++ libraries to manipulate images in these formats:
.jpg .gif .png .bmp ? The more formats it supports, the better. I am implementing a free program in C++ which hides a text file into one or more images, using steganography.
I am working under Unix.
ImageMagick can manipulate about anything and has interfaces for a dozen of languages, including the Magick++ API for C++.
#lurks: I assume that you are looking for LSB shifting? I did some stego work a couple of years ago, and that's how it appeared most apps worked. It appears that ImageMagick (suggested by others) allows you to identify and manipulate the LSBs.
It takes some setting up, but I'm a fan of Adobe's GIL (now part of Boost).
Have you considered GDI?
-- Kevin Fairchild
FreeImage is pretty solid. It has a C interface but is more C++-like in its implementation.
For .png images you could look into Cairo (and CairoMM). There's also Anti-Grain which people consider very fast.
I like vxl
VXL (the Vision-something-Libraries) is a collection of C++ libraries designed for computer vision research and implementation. It was created from TargetJr and the IUE with the aim of making a light, fast and consistent system. VXL is written in ANSI/ISO C++ and is designed to be portable over many platforms.