1. 程式人生 > >C# 圖片轉換為base64

C# 圖片轉換為base64

blog length request esp read 驗證碼 orm rom for

 WebRequest webRequest = WebRequest.Create("驗證碼url");
            WebResponse webResponse = webRequest.GetResponse();
            Stream stream = webResponse.GetResponseStream();
            string cookie = webResponse.Headers.Get("Set-Cookie");
            Image img = Bitmap.FromStream(stream);
            pictureBox1.Image = img;
            using (MemoryStream ms1 = new MemoryStream())
            {
                img.Save(ms1, System.Drawing.Imaging.ImageFormat.Jpeg);
                byte[] arr1 = new byte[ms1.Length];
                ms1.Position = 0;
                ms1.Read(arr1, 0, (int)ms1.Length);
                ms1.Close();
                textBox1.Text = Convert.ToBase64String(arr1);
            }

  因為要做驗證碼識別第三方接口對接 需要將圖片轉換為base64傳遞參數 記錄一下

C# 圖片轉換為base64