private void writeImageData(DataOutputStream out) throws IOException {
        int index;
        int padding = 0;
        int overage = biWidth % 4;
        if ( overage != 0 )
            padding = 4 - overage;
        for ( int y = biHeight - 1; y >= 0; y-- )
        {
            index = y * biWidth;
            for ( int x = 0; x < biWidth; x++ )
            {
                out.writeByte(pix[index++]);
            }
            if ( padding != 0 ) {
                for ( int i = 0; i < padding; i++) {
                    out.writeByte(0);
                }
            }
        }
        
    }