Пример #1
0
wxBitmap LoadScaledBitmap(const wxString& name)
{
    const wxString filename(name + ".png");
    if (!wxFileExists(filename))
        return wxNullBitmap;

#ifdef NEEDS_MANUAL_HIDPI
    if (HiDPIScalingFactor() > 1.0)
    {
        wxImage img;
        double imgScale = HiDPIScalingFactor();
        const wxString filename_2x(name + "@2x.png");
        if (wxFileExists(filename_2x))
        {
            LoadPNGImage(img, filename_2x);
            if (HiDPIScalingFactor() == 2.0)
                return wxBitmap(img);
            else
                imgScale /= 2.0;
        }
        else
        {
            LoadPNGImage(img, filename);
        }

        img.Rescale(img.GetWidth() * imgScale, img.GetHeight() * imgScale,
                    imgScale == 2.0 ? wxIMAGE_QUALITY_NEAREST : wxIMAGE_QUALITY_BICUBIC);
        return wxBitmap(img);
    }
    // else: load normally
#endif

    return wxBitmap(wxImage(filename, wxBITMAP_TYPE_PNG));
}
Пример #2
0
wxImage LoadScaledBitmap(const wxString& name)
{
    const wxString filename(name + ".png");
    if (!wxFileExists(filename))
        return wxNullImage;

    wxImage img;

#ifdef NEEDS_MANUAL_HIDPI
    // On Windows, arbitrary scaling factors are possible and "ugly" values like 125%
    // or 150% scaling are not only possible, but common. It is unrealistic to provide
    // custom-drawn bitmaps for all of them, so we make do with a basic set of 100%/@1x,
    // 200%/@2x (used on macOS too) and one more for 150%/@1.5x for Windows use.
    // To eliminate smudged scaling artifacts, we use these fixed sizes even for zoom
    // factors in-between (such as the very common 125% or less common 175%). This looks
    // better and the size difference is negligible.
    auto const screenScaling = HiDPIScalingFactor();
    if (screenScaling > 1.25)
    {
        if (screenScaling <= 1.75)  // @1.5x is reasonable 
        {
            const wxString filename_15x(name + "@1.5x.png");
            if (wxFileExists(filename_15x))
            {
                LoadPNGImage(img, filename_15x);
                if (img.IsOk())
                    return img;
            }
        }

        double imgScale = screenScaling;
        const wxString filename_2x(name + "@2x.png");
        if (wxFileExists(filename_2x))
        {
            LoadPNGImage(img, filename_2x);
            if (screenScaling > 1.75 && screenScaling <= 2.50)  // @2x is reasonable
                return img;
            else
                imgScale /= 2.0;
        }
        else  // fall back to upscaled @1x
        {
            LoadPNGImage(img, filename);
        }

        if (!img.IsOk())
            return wxNullImage;

        wxImageResizeQuality quality;
        if (imgScale == 2.0)
            quality = wxIMAGE_QUALITY_NEAREST;
        else if (imgScale == 1.5)
            quality = wxIMAGE_QUALITY_BILINEAR;
        else
            quality = wxIMAGE_QUALITY_BICUBIC;
        img.Rescale(img.GetWidth() * imgScale, img.GetHeight() * imgScale, quality);
        return img;
    }
    // else if screenScaling <= 1.25: @1x size is good enough, load normally
#endif

    LoadPNGImage(img, filename);
    return img;
}