而且要能转回,应该用什么办法,谢谢

解决方案 »

  1.   

    序列化,反序列化图片只能赚成流 也就是stream,然后通过编码转换为字符串。
      

  2.   

    用Stream方式读取,然后Base64编码方法保存即可。
      

  3.   

    可以使用Convert.ToBase64String 方法 (Byte[])

    Convert.FromBase64String 方法 
    来对二进制数据和字符串相互转换:下面的代码示例演示如何使用 ToBase64CharArray 方法对二进制流进行 UUencode (base 64) 编码,然后将编码保存到文件中。public void EncodeWithCharArray() {
        System.IO.FileStream inFile;     
        byte[]                 binaryData;    try {
            inFile = new System.IO.FileStream(inputFileName,
                                              System.IO.FileMode.Open,
                                              System.IO.FileAccess.Read);
            binaryData = new Byte[inFile.Length];
            long bytesRead = inFile.Read(binaryData, 0,
                                        (int) inFile.Length);
            inFile.Close();
        }
        catch (System.Exception exp) {
            // Error creating stream or reading from it.
            System.Console.WriteLine("{0}", exp.Message);
            return;
        }    // Convert the binary input into Base64 UUEncoded output.
        // Each 3 byte sequence in the source data becomes a 4 byte
        // sequence in the character array. 
        long arrayLength = (long) ((4.0d/3.0d) * binaryData.Length);
        
        // If array length is not divisible by 4, go up to the next
        // multiple of 4.
        if (arrayLength % 4 != 0) {
            arrayLength += 4 - arrayLength % 4;
        }
        
        char[] base64CharArray = new char[arrayLength];
        try {
            System.Convert.ToBase64CharArray(binaryData, 
                                             0,
                                             binaryData.Length,
                                             base64CharArray,
                                             0);
        }
        catch (System.ArgumentNullException) {
            System.Console.WriteLine("Binary data array is null.");
            return;
        }
        catch (System.ArgumentOutOfRangeException) {
            System.Console.WriteLine("Char Array is not large enough.");
            return;
        }    // Write the UUEncoded version to the output file.
        System.IO.StreamWriter outFile; 
        try {
            outFile = new System.IO.StreamWriter(outputFileName,
                                            false,
                                            System.Text.Encoding.ASCII);             
            outFile.Write(base64CharArray);
            outFile.Close();
        }
        catch (System.Exception exp) {
            // Error creating stream or writing to it.
            System.Console.WriteLine("{0}", exp.Message);
        }
    }
    下面的代码示例演示如何使用 FromBase64String 方法对以 UUencode (base 64) 编码的数据进行解码并将它保存为二进制输出。public void DecodeWithString() {
        System.IO.StreamReader inFile;     
        string base64String;    try {
            char[] base64CharArray;
            inFile = new System.IO.StreamReader(inputFileName,
                                            System.Text.Encoding.ASCII);
            base64CharArray = new char[inFile.BaseStream.Length];
            inFile.Read(base64CharArray, 0, (int)inFile.BaseStream.Length);
            base64String = new string(base64CharArray);
        }
        catch (System.Exception exp) {
            // Error creating stream or reading from it.
            System.Console.WriteLine("{0}", exp.Message);
            return;
        }    // Convert the Base64 UUEncoded input into binary output.
        byte[] binaryData;
        try {
            binaryData = 
                System.Convert.FromBase64String(base64String);
        }
        catch (System.ArgumentNullException) {
            System.Console.WriteLine("Base 64 string is null.");
            return;
        }
        catch (System.FormatException) {
            System.Console.WriteLine("Base 64 string length is not " +
                "4 or is not an even multiple of 4." );
            return;
        }    // Write out the decoded data.
        System.IO.FileStream outFile;
        try {
            outFile = new System.IO.FileStream(outputFileName,
                                               System.IO.FileMode.Create,
                                               System.IO.FileAccess.Write);
            outFile.Write(binaryData, 0, binaryData.Length);
            outFile.Close();
        }
        catch (System.Exception exp) {
            // Error creating stream or writing to it.
            System.Console.WriteLine("{0}", exp.Message);
        }
    }
      

  4.   

     hbxtlhx
    ----------
    支持