Estoy tratando de capturar la pantalla y luego convertirla en una cadena Base64. Este es mi código:Cómo convertir el mapa de bits a una cadena Base64?
Rectangle bounds = Screen.GetBounds(Point.Empty);
Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height);
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
}
// Convert the image to byte[]
System.IO.MemoryStream stream = new System.IO.MemoryStream();
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] imageBytes = stream.ToArray();
// Write the bytes (as a string) to the textbox
richTextBox1.Text = System.Text.Encoding.UTF8.GetString(imageBytes);
// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
El uso de un RichTextbox de depurar, se nota:
BM6 ~
Así que por alguna razón los bytes no son correctas, que hace que el base64String ser nulo ¿Alguna idea de lo que estoy haciendo mal? Gracias.
Ah, woops. Gracias Tim :) –