Hack Forums
[C#] Trying to add screenshots to lite http bot - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] Trying to add screenshots to lite http bot (/showthread.php?tid=5831141)



Trying to add screenshots to lite http bot - icemanonadderall - Apr 29, 2018

Whats the best way to take a screenshot for a bot? Should I store the screenshots in the temp dir then upload them to my panel?


RE: Trying to add screenshots to lite http bot - gigajew - Apr 29, 2018

There's no reason to save them first. Keep it in memory and just upload it


RE: Trying to add screenshots to lite http bot - gigajew - May 1, 2018

Here's an example I made one time https://hackforums.net/showthread.php?tid=5804711&pid=56745560#pid56745560


RE: Trying to add screenshots to lite http bot - icemanonadderall - May 13, 2018

(May 1, 2018 03:22 PM)gigajew Wrote:  Here's an example I made one time https://hackforums.net/showthread.php?tid=5804711&pid=56745560#pid56745560

Thanks for the example code.


RE: Trying to add screenshots to lite http bot - Raiden69 - May 16, 2018

Here's how I take a screenshot using native methods.

Code
[DllImport("gdi32.dll")]
private static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
public static Bitmap GetScreenCapture(Rectangle fov)
{
    Bitmap bmp = new Bitmap(fov.Width, fov.Height, PixelFormat.Format24bppRgb);

    using (Graphics gfxBmp = Graphics.FromImage(bmp))
    using (Graphics gfxHwnd = Graphics.FromHwnd(IntPtr.Zero))
    {
        IntPtr hSrcDc = gfxHwnd.GetHdc();
        IntPtr hDc = gfxBmp.GetHdc();
        BitBlt(hDc, 0, 0, fov.Width, fov.Height, hSrcDc, fov.X, fov.Y, (int)CopyPixelOperation.SourceCopy);

        gfxBmp.ReleaseHdc();
        gfxHwnd.ReleaseHdc();
    }

    return bmp;
}

If I were you I'd upload them on the fly yes. Before uploading I would consider resizing (to a smaller size) and also compression. Have a look at System.IO.Compression (DeflateStream class) or alternatively you can do something dirty such as save the image on the hard disk as a lossy/high compression format such as jpg and upload that without having to write any compression code yourself.


RE: Trying to add screenshots to lite http bot - Cød3ing - May 17, 2018

(May 16, 2018 11:56 PM)Raiden69 Wrote:  Here's how I take a screenshot using native methods.

It doesn't really matter what method you use with C# because there's no such thing as "lite" or "native"


RE: Trying to add screenshots to lite http bot - Dalvik - May 17, 2018

(May 17, 2018 12:36 AM)Cod3ing® Wrote:  It doesn't really matter what method you use with C# because there's no such thing as "lite" or "native"

There are more efficient/faster ways to work with bitmaps using unsafe code as compared to 'normal' methods. For example, there are unsafe alternatives to GetPixel that work much more efficiently.


RE: Trying to add screenshots to lite http bot - peterkakol - May 17, 2018

Create file in TEMP or APP data then upload and delete. Use exception handling for error. on exception occurs, delete file and close streams etc


RE: Trying to add screenshots to lite http bot - Raiden69 - May 17, 2018

(May 17, 2018 12:36 AM)Cod3ing® Wrote:  It doesn't really matter what method you use with C# because there's no such thing as "lite" or "native"

Did not say that it makes a difference. CopyFromScreen still interfaces with BitBlt, it's just a personal preference (+ might potentially save on some overhead by using Win32 directly rather than a subset of it/something much higher up).
There is such a thing as calling native functions/PInvoke from managed code...


RE: Trying to add screenshots to lite http bot - Dalvik - May 19, 2018

(May 17, 2018 12:36 AM)Cod3ing® Wrote:  It doesn't really matter what method you use with C# because there's no such thing as "lite" or "native"

https://docs.microsoft.com/en-us/dotnet/framework/net-native/