I have a server-client application, i want to get a Screen Shot from server,but on the line bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
i get this exception : A generic error occurred in GDI+.
private Socket ScreenSocket;
private MemoryStream ms;
public void ConnectScreenShot(IPEndPoint ep)
{
if (ScreenSocket != null)
{
ScreenSocket.Dispose();
ScreenSocket = null;
}
if (ms != null)
{
ms.Dispose();
ms = null;
}
ScreenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
ScreenSocket.Connect(ep);
ms = new MemoryStream();
Rectangle bounds = Screen.GetBounds(Point.Empty);
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(Point.Empty, Point.Empty, bitmap.Size);
}
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
}
}
Why is that happening and how would i fix it?
Update: It works when i use ImageFormat.Jpeg
Instead of ImageFormat.Png
, but i still need a PNG format.