Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Trying to add screenshots to lite http bot

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?
There's no reason to save them first. Keep it in memory and just upload it
[Image: Syr3DlV.png]
Here's an example I made one time https://hackforums.net/showthread.php?ti...id56745560
[Image: Syr3DlV.png]
(May 1, 2018 03:22 PM)gigajew Wrote:  Here's an example I made one time https://hackforums.net/showthread.php?ti...id56745560

Thanks for the example code.
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.
(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"
(May 17, 2018 12:36 AM)Cød3ing 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.
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
(May 17, 2018 12:36 AM)Cød3ing 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...
(May 17, 2018 12:36 AM)Cød3ing 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/...et-native/


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by anthoo12Feb 2, 2018 11:46 PM 16 2,061 Feb 2, 2018 11:46 PM
Last Post: v.e.n.o.m
[.NET] by BarretJan 16, 2018 02:44 PM 6 432 Jan 16, 2018 02:44 PM
Last Post: Ninja
[.NET] by DANKMEMEBOYDec 14, 2017 03:50 AM 6 321 Dec 14, 2017 03:50 AM
Last Post: goregasmx