From f47f44350dd118111ea1b58aa2234c99ec639ba9 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 23 Apr 2023 11:30:02 +0200 Subject: [PATCH] BITMAP_BASE::Mirror() and ::Rotate(): fix an issue for bitmaps with ppi not 300 wxImage::Mirror() and wxImage::Rotate() transforms clear some parameters, especially the PPI stored in the image. It creates bad size (bad ppi) when saving a BITMAP_BASE in files. These parameters are now restored after transform. --- common/bitmap_base.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/common/bitmap_base.cpp b/common/bitmap_base.cpp index ffede07364..99c8f38fd4 100644 --- a/common/bitmap_base.cpp +++ b/common/bitmap_base.cpp @@ -400,7 +400,20 @@ void BITMAP_BASE::Mirror( bool aVertically ) { if( m_image ) { + // wxImage::Mirror() clear some parameters of the original image. + // We need to restore them, especially resolution and unit, to be + // sure image parameters saved in file are the right parameters, not + // the defualt values + int resX = m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONX ); + int resY = m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONY ); + int unit = m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT ); + *m_image = m_image->Mirror( not aVertically ); + + m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONUNIT , unit); + m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONX, resX); + m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONY, resY); + m_isMirrored = !m_isMirrored; rebuildBitmap( false ); } @@ -411,7 +424,20 @@ void BITMAP_BASE::Rotate( bool aRotateCCW ) { if( m_image ) { + // wxImage::Rotate90() clear some parameters of the original image. + // We need to restore them, especially resolution and unit, to be + // sure image parameters saved in file are the right parameters, not + // the defualt values + int resX = m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONX ); + int resY = m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONY ); + int unit = m_image->GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT ); + *m_image = m_image->Rotate90( aRotateCCW ); + + m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONUNIT , unit); + m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONX, resX); + m_image->SetOption( wxIMAGE_OPTION_RESOLUTIONY, resY); + m_rotation += ( aRotateCCW ? -ANGLE_90 : ANGLE_90 ); rebuildBitmap( false ); }