private void scaleBackgroundImage(CssContext c, CalculatedStyle style, Rectangle backgroundContainer, FSImage image) { BackgroundSize backgroundSize = style.getBackgroundSize(); if (! backgroundSize.isBothAuto()) { if (backgroundSize.isCover() || backgroundSize.isContain()) { int testHeight = (int)((double)image.getHeight() * backgroundContainer.width / image.getWidth()); if (backgroundSize.isContain()) { if (testHeight > backgroundContainer.height) { image.scale(-1, backgroundContainer.height); } else { image.scale(backgroundContainer.width, -1); } } else if (backgroundSize.isCover()) { if (testHeight > backgroundContainer.height) { image.scale(backgroundContainer.width, -1); } else { image.scale(-1, backgroundContainer.height); } } } else { int scaledWidth = calcBackgroundSizeLength(c, style, backgroundSize.getWidth(), backgroundContainer.width); int scaledHeight = calcBackgroundSizeLength(c, style, backgroundSize.getHeight(), backgroundContainer.height); image.scale(scaledWidth, scaledHeight); } } }