Composite Image ignoring transparency

56 views
Skip to first unread message

pok

unread,
Oct 5, 2010, 8:41:34 PM10/5/10
to google-a...@googlegroups.com
I'm trying to create a composite image, but it seems like it is ignoring any alpha channels and transparency.  I looked through the forums, some people say their is a bug in the dev sdk, so I tried it on google server too, similar results.

I've uploading the images and results in this post.  The code basically uses the bg.png (the white is transparent) as background and overlays test.png  (the white is transparent) over it, the results from the local dev server (local.png) is wrong, uploading the app to google app engine, the result is different, but is also wrong (remote.png).  Is this a bug or is there something wrong with my code below?

[code]

public class CreateImageServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        doOutput(req, resp);
    }
   
    private void doOutput(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ImagesService service = ImagesServiceFactory.getImagesService();
       
        Image bg = ImagesServiceFactory.makeImage(getImage("bg.png"));
        Image over = ImagesServiceFactory.makeImage(getImage("test.png"));
       
        List<Composite> composites = new ArrayList<Composite>();
        composites.add(ImagesServiceFactory.makeComposite(bg, 0, 0, 1, Anchor.TOP_LEFT));
        composites.add(ImagesServiceFactory.makeComposite(over, 0, 0, 1, Anchor.TOP_LEFT));
        Image image = service.composite(composites, bg.getWidth(), bg.getHeight(), 0, OutputEncoding.PNG);

        resp.setContentType("image/png");
        resp.getOutputStream().write(image.getImageData());
    }
   
   
    private byte[] getImage(String resource) throws IOException {
        InputStream is = getClass().getResourceAsStream(resource);
        try {
            ByteArrayOutputStream os = new ByteArrayOutputStream(1024*6);
            byte[] buf = new byte[1024];
            int read;
           
            while ( (read=is.read(buf)) != -1 ) {
                os.write(buf, 0, read);
            }
           
        return os.toByteArray();
        } finally {
            is.close();
        }
    }

}

[/code]
bg.png
test.png
local.png
remote.png
Reply all
Reply to author
Forward
0 new messages