X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dcc36b34be1e1492894a5be7a027d99d3e74ebd9..0bd2681966523df88ad5cf8e505b532843e58d74:/src/common/imagpng.cpp diff --git a/src/common/imagpng.cpp b/src/common/imagpng.cpp index 009f133de9..bb081b809a 100644 --- a/src/common/imagpng.cpp +++ b/src/common/imagpng.cpp @@ -748,6 +748,33 @@ bool wxPNGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbos if ( iBitDepth == 16 ) iElements *= 2; + // save the image resolution if we have it + int resX, resY; + switch ( GetResolutionFromOptions(*image, &resX, &resY) ) + { + case wxIMAGE_RESOLUTION_INCHES: + { + const double INCHES_IN_METER = 10000.0 / 254; + resX = int(resX * INCHES_IN_METER); + resY = int(resY * INCHES_IN_METER); + } + break; + + case wxIMAGE_RESOLUTION_CM: + resX *= 100; + resY *= 100; + break; + + case wxIMAGE_RESOLUTION_NONE: + break; + + default: + wxFAIL_MSG( _T("unsupported image resolution units") ); + } + + if ( resX && resY ) + png_set_pHYs( png_ptr, info_ptr, resX, resY, PNG_RESOLUTION_METER ); + png_set_sBIT( png_ptr, info_ptr, &sig_bit ); png_write_info( png_ptr, info_ptr ); png_set_shift( png_ptr, &sig_bit );