public void draw(int x, int y, Graphics2D g)
    {
        GraphicsConfiguration config = g.getDeviceConfiguration();
        
        if (vi == null)
        {
            vi = config.createCompatibleVolatileImage(bi.getWidth(), bi.getHeight(), quality);
            drawToVolatileImage(config);
        }
        do
        {
            int code = vi.validate(config);
            if (code == VolatileImage.IMAGE_RESTORED)
            {
                drawToVolatileImage(config);
            }
            else if (code == VolatileImage.IMAGE_INCOMPATIBLE)
            {
                vi = config.createCompatibleVolatileImage(bi.getWidth(), bi.getHeight(), quality);
                drawToVolatileImage(config);
            }
            
            if (transparency != 0)
            {
                AffineTransform prev = g.getTransform();
                g.transform(transform);
                g.drawImage(vi, (int)(x/transform.getScaleX()), (int)(y/transform.getScaleY()),
                        null);
                g.setTransform(prev);
            }
        } while (vi.contentsLost());
    }