From 7ba6220216a8d811561f32b28fca2c9b2ef33ed0 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Wed, 3 Mar 2004 14:20:13 +0000 Subject: [PATCH] Only scale an image once, which vastly improves the appearance of scaled images in print and preview git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26059 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/html/m_image.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/html/m_image.cpp b/src/html/m_image.cpp index a142580cd4..58aaa45e23 100644 --- a/src/html/m_image.cpp +++ b/src/html/m_image.cpp @@ -464,12 +464,16 @@ void wxHtmlImageCell::SetImage(const wxImage& img) if ( m_bmpH == -1 ) m_bmpH = hh; + // Only scale the bitmap at the rendering stage, + // so we don't lose quality twice +/* if ((m_bmpW != ww) || (m_bmpH != hh)) { wxImage img2 = img.Scale(m_bmpW, m_bmpH); m_bitmap = new wxBitmap(img2); } else +*/ m_bitmap = new wxBitmap(img); } } @@ -547,12 +551,21 @@ void wxHtmlImageCell::Draw(wxDC& dc, int x, int y, } if ( m_bitmap ) { + // We add in the scaling from the desired bitmap width + // and height, so we only do the scaling once. + double imageScaleX = 1.0; + double imageScaleY = 1.0; + if (m_bmpW != m_bitmap->GetWidth()) + imageScaleX = (double) m_bmpW / (double) m_bitmap->GetWidth(); + if (m_bmpH != m_bitmap->GetHeight()) + imageScaleY = (double) m_bmpH / (double) m_bitmap->GetHeight(); + double us_x, us_y; dc.GetUserScale(&us_x, &us_y); - dc.SetUserScale(us_x * m_scale, us_y * m_scale); + dc.SetUserScale(us_x * m_scale * imageScaleX, us_y * m_scale * imageScaleY); - dc.DrawBitmap(*m_bitmap, (int) ((x + m_PosX) / m_scale), - (int) ((y + m_PosY) / m_scale), TRUE); + dc.DrawBitmap(*m_bitmap, (int) ((x + m_PosX) / (m_scale*imageScaleX)), + (int) ((y + m_PosY) / (m_scale*imageScaleY)), TRUE); dc.SetUserScale(us_x, us_y); } } -- 2.45.2