public void sendString_Base64_ReturnImage()
        {
            //A
            Image  result;
            var    tProces   = new Base64();
            string imgBase64 = tProces.ImageToBase64(TestImagePath, ImageFormat.Jpeg);

            //A
            result = tProces.Base64ToImage(imgBase64, 0);   // ver el tema de ImageFormat.Jpeg

            //A
            Assert.AreEqual(result.GetType(), typeof(Bitmap));
        }
Ejemplo n.º 2
0
        public static string ConsultaPerfil(string username, out User consultado)
        {
            consultado = new User();

            try
            {
                XDocument xmlResposta = GetService(EndPoint.GetPerfil, new string[] { username });
                // ...interpretar o resultado de acordo com a lógica da aplicação (exemplificativo)
                if (xmlResposta.Element("resultado").Element("status").Value == "ERRO")
                {
                    consultado = null;

                    //// apresenta mensagem de erro usando o texto (contexto) da resposta
                    //MessageBox.Show(
                    //xmlResposta.Element("resultado").Element("contexto").Value,
                    //"Erro",
                    //MessageBoxButtons.OK,
                    //MessageBoxIcon.Error 29.    );

                    return("ERROR");
                }
                else
                {
                    string nomeAbreviado = GetValueFromElement(xmlResposta.Element("resultado").Element("objeto").Element("perfil").Element("nomeabreviado"));

                    string email = GetValueFromElement(xmlResposta.Element("resultado").Element("objeto").Element("perfil").Element("email"));

                    string pais = GetValueFromElement(xmlResposta.Element("resultado").Element("objeto").Element("perfil").Element("pais"));

                    string jogosGanhos = GetValueFromElement(xmlResposta.Element("resultado").Element("objeto").Element("perfil").Element("jogos").Element("ganhos"));

                    string jogosPerdidos = GetValueFromElement(xmlResposta.Element("resultado").Element("objeto").Element("perfil").Element("jogos").Element("perdidos"));

                    string bestTimeEasy = GetValueFromElement(xmlResposta.Element("resultado").Element("objeto").Element("perfil").Element("tempos").Element("Facil"));

                    string bestTimeMedium = GetValueFromElement(xmlResposta.Element("resultado").Element("objeto").Element("perfil").Element("tempos").Element("Medio"));

                    string base64Imagem = GetValueFromElement(xmlResposta.Element("resultado").Element("objeto").Element("perfil").Element("fotografia"));

                    consultado.Username       = nomeAbreviado;
                    consultado.Email          = (email);
                    consultado.Country        = pais;
                    consultado.WinStats       = Convert.ToInt32(jogosGanhos);
                    consultado.LoseStats      = Convert.ToInt32(jogosPerdidos);
                    consultado.BestTimeEasy   = bestTimeEasy;
                    consultado.BestTimeMedium = bestTimeMedium;

                    if (base64Imagem != string.Empty)
                    {
                        consultado.PerfilBase64 = base64Imagem;
                        consultado.Perfil       = Base64.Base64ToImage(base64Imagem);
                    }

                    //if (base64Imagem != string.Empty)
                    //{
                    //	string base64 = base64Imagem.Split(',')[1]; // retira a parte da string correspondente aos bytes da imagem..
                    //	byte[] bytes = Convert.FromBase64String(base64); //...converte para array de bytes...
                    //	System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(bytes));
                    //	consultado.Perfil = image;
                    //}
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return("OK");
        }