std::stringstream out;
std::streambuf * old = std::cout.rdbuf();
std::cout.rdbuf(out.rdbuf());
DiJPEGPlugin plugin;
plugin.setQuality(OFstatic_cast(unsigned int, opt_quality));
plugin.setSampling(opt_sampling);
int result = di->writePluginFormat(&plugin, stdout, frameNumber);
std::cout.rdbuf(old);
The result is true, but the size of stringstream is 0.
I'm working under Windows. I think that the stdout is not correctly redirect to my buffer. Is it possible?
As far as I remember, the standard output stream on Windows does not support binary information very well (or is at least by default not opened in binary mode).
However, there is a define that can be enabled for this purpose. The following excerpt is from "config/docs/macro.txt":
USE_BINARY_MODE_FOR_STDOUT_ON_WINDOWS
Affected: dcmdata
Type of modification: Activates experimental or rarely used feature
Explanation: On Windows systems, the standard output (stdout) is opened in
text mode by default. Therefore, the binary output of tools like dcm2pnm
to stdout does not work correctly (in contrast to Unix systems). When
this preprocessor macro is defined, the binary mode is enabled for stdout.
However, this causes newlines in the textual output to be converted to LF
only (instead of CR LF which would be the usual translation for Windows).
My personal opinion is: Don't open "stdout" in binary mode (on Windows).