I want to take screenshot using C# for multiple screen games of high definition.It works normally very good but if I am going to take the screenshot of full screen graphics games it shows a black rectangle box.I have googled a lot but did't got any proper solution.So could any one give a solution for that its very urgent for me.More over I have not work with directX .More over my project is in .Net framework 4.5.
Please help me with a proper code example.That is workable regarding this..please guys.
What I have tried:
I have used C# for that.My code is:
string ScreenPath,directory;
code to initialize:
string appPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "anticheat");
try
{
if (!Directory.Exists(appPath))
{
Directory.CreateDirectory(appPath);
}
}
catch(Exception)
{
}
directory = appPath;
-------------------------------------------
code to capture image
public void screenCapture(bool showCursor)
{
int noofscreens = 0;
Screen[] screens;
screens = Screen.AllScreens;
noofscreens = screens.Length;
Point curPos = new Point(Cursor.Position.X, Cursor.Position.Y);
Size curSize = new Size();
curSize.Height = Cursor.Current.Size.Height;
curSize.Width = Cursor.Current.Size.Width;
string foldername = LoginFrm.username;
ScreenPath = directory +"/"+foldername.Replace('@', '_')+"-"+ DateTime.Now.ToString("dd-MMM-yyy hh-mm-ss tt") + ".jpg";
if (!ScreenShot.saveToClipboard)
{
}
if (ScreenPath != "" || ScreenShot.saveToClipboard)
{
System.Threading.Thread.Sleep(250);
Rectangle bounds = Screen.GetBounds(Screen.GetBounds(Point.Empty));
string fi = "";
if (ScreenPath != "")
{
fi = new FileInfo(ScreenPath).Extension;
}
System.Threading.Thread.Sleep(100);
int i = 0;
foreach (var screen in System.Windows.Forms.Screen.AllScreens)
{
ScreenPath = directory + "/" + foldername.Replace('@', '_') + "-" + DateTime.Now.ToString("dd-MMM-yyy hh-mm-ss tt") + "_Sc(" + (i +1)+ ")" + ".jpg";
Rectangle bounds1 = screen.Bounds;
ScreenShot.CaptureImage(showCursor, curSize, curPos, Point.Empty, Point.Empty, bounds1, ScreenPath, fi);
i++;
}
if (ScreenShot.saveToClipboard)
{
}
else
{
}
}
}
---------------------------------------
class ScreenShot
{
public static bool saveToClipboard = false;
public static void CaptureImage(bool showCursor, Size curSize, Point curPos, Point SourcePoint, Point DestinationPoint, Rectangle SelectionRectangle, string FilePath, string extension)
{
DataLayer dl = new DataLayer();
string ftp = "my Serverpath";
if(LoginFrm.username!="")
{
folder = folder + LoginFrm.username + "/";
}
SourcePoint = new Point(SelectionRectangle.X, SelectionRectangle.Y);
using (Bitmap bitmap = new Bitmap(SelectionRectangle.Width, SelectionRectangle.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(SourcePoint, DestinationPoint, SelectionRectangle.Size);
if (showCursor)
{
Rectangle cursorBounds = new Rectangle(curPos, curSize);
Cursors.Default.Draw(g, cursorBounds);
}
}
if (saveToClipboard)
{
Image img = (Image)bitmap;
Clipboard.SetImage(img);
}
else
{
switch (extension)
{
case ".bmp":
bitmap.Save(FilePath, ImageFormat.Bmp);
break;
case ".jpg":
bitmap.Save(FilePath, ImageFormat.Jpeg);
string fname = Path.GetFileName(FilePath);
break;
case ".gif":
bitmap.Save(FilePath, ImageFormat.Gif);
dl.UploadFile(ftp, folder, username, psw, FilePath);
break;
case ".tiff":
bitmap.Save(FilePath, ImageFormat.Tiff);
dl.UploadFile(ftp, folder, username, psw, FilePath);
break;
case ".png":
bitmap.Save(FilePath, ImageFormat.Png);
dl.UploadFile(ftp, folder, username, psw, FilePath);
break;
default:
bitmap.Save(FilePath, ImageFormat.Jpeg);
dl.UploadFile(ftp, folder, username, psw, FilePath);
break;
}
}
}
}
}