--- old/src/java.desktop/share/classes/sun/java2d/pipe/DrawImage.java 2016-03-02 16:43:59.835456000 +0530 +++ new/src/java.desktop/share/classes/sun/java2d/pipe/DrawImage.java 2016-03-02 16:43:59.567322000 +0530 @@ -430,9 +430,9 @@ if (isBgOperation(srcData, bgColor)) { // We cannot perform bg operations during transform so make - // an opaque temp image with the appropriate background + // a temp image with the appropriate background // and work from there. - img = makeBufferedImage(img, bgColor, BufferedImage.TYPE_INT_RGB, + img = makeBufferedImage(img, bgColor, BufferedImage.TYPE_INT_ARGB, sx1, sy1, sx2, sy2); // Temp image has appropriate subimage at 0,0 now. sx2 -= sx1; --- /dev/null 2016-03-02 14:33:16.377500000 +0530 +++ new/test/java/awt/image/DrawImage/ScaledImageAlphaTest.java 2016-03-02 16:44:00.303689999 +0530 @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8139183 + * @summary Test verifies whether alpha channel of a translucent + * image is proper or not after scaling through drawImage. + * @run main ScaledImageAlphaTest + */ + +import java.awt.*; +import java.awt.image.*; + +public class ScaledImageAlphaTest { + + public static void main(String[] args){ + + int width = 50, height = 50; + // create BufferedImage of dimension (50,50) + BufferedImage img = new + BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + Graphics2D imgGraphics = (Graphics2D)img.getGraphics(); + + int scaleX = 5, scaleY = 5, scaleWidth = 40, scaleHeight = 40; + int translucentAlpha = 128; + + /* scale image to smaller dimension and set background color + * to green with translucent alpha. + */ + Color translucentGreen = new Color(0, 255, 0, translucentAlpha); + imgGraphics. + drawImage(img, scaleX, scaleY, scaleWidth, scaleHeight, + translucentGreen, null); + imgGraphics.dispose(); + + /* get pixel information for background green color with + * scaled coordinates and extract alpha. + */ + Color c = new Color(img.getRGB(scaleX, scaleY), true); + int alpha = c.getAlpha(); + + /* if alpha value is translucent, alpha channel is not lost + * while scaling otherwise we have lost alpha channel. + */ + if(alpha != translucentAlpha) { + throw new RuntimeException("Alpha channel is lost while scaling"); + } + } +}