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.
This commit is contained in:
jean-pierre charras 2023-04-23 11:30:02 +02:00
parent c617abe8e9
commit f47f44350d
1 changed files with 26 additions and 0 deletions

View File

@ -400,7 +400,20 @@ void BITMAP_BASE::Mirror( bool aVertically )
{ {
if( m_image ) 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 = 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; m_isMirrored = !m_isMirrored;
rebuildBitmap( false ); rebuildBitmap( false );
} }
@ -411,7 +424,20 @@ void BITMAP_BASE::Rotate( bool aRotateCCW )
{ {
if( m_image ) 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 = 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 ); m_rotation += ( aRotateCCW ? -ANGLE_90 : ANGLE_90 );
rebuildBitmap( false ); rebuildBitmap( false );
} }