Bonjour !

Je cherche à envoyer une image via une connexion TCP Client/Serveur.
La connexion ne déroule parfaitement et les transferts aussi.

Pour envoyer mon image, je souhaite la convertir en tableau de Byte[] puis en string Base64 via ce code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
public void PrintScreen()
        {
            Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height);
            Graphics graphics = Graphics.FromImage(bitmap as Image);
            graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
 
            byte[] bytesend = ImageToByte(bitmap);
            string s = Convert.ToBase64String(bytesend);
 
            SEND("I/" + s);
        }
 
        public static byte[] ImageToByte(Image img)
        {
            ImageConverter converter = new ImageConverter();
            return (byte[])converter.ConvertTo(img, typeof(byte[]));
        }
L'envoi se fait avec
NB: Lorsque je recupère ma chaine du coté serveur, je fait un split pour ne prendre que la partie après le I/

Par la suite j'essaye de convertir ma chaine Base64 en Byte[].

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
public void ShowImage(string Base64Str)
        {
            byte[] newBytes = Convert.FromBase64String(Base64Str);
            Image img = byteArrayToImage(newBytes);
        }
Et c'est ici que j'ai un message d'erreur : Longueur non valide pour un tableau bytes Base64 ou string.

J'ai essayer d'afficher la string Base64Str avant, et elle est bien au format base64.

J'ai cherché sur internet, sans trouver de solution qui fonctionne...

Merci de votre aide

Ind6x