Trying to take a screen capture of a game running in BlueStacks using C# menu

User Tag List

Results 1 to 1 of 1
  1. #1
    Lochnar's Avatar Member
    Reputation
    1
    Join Date
    Jul 2016
    Posts
    1
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trying to take a screen capture of a game running in BlueStacks using C#

    The code works fine when the target game is running on the version installed from the Windows App Store. The game is a port from an Android game and the Windows version is not receiving updates anymore so I want to run the Android version which is newer using BlueStacks on my PC.

    This is the code that works with native Windows version of the game.

    public GameWindow(int titleHeight)
    {
    GetGameWindow();
    TitleHeight = titleHeight;
    }

    private void GetGameWindow()
    {
    Form1.Rect rectangle = default(Form1.Rect);
    IntPtr intPtr = FindWindow("ApplicationFrameWindow", "Game Window");
    SetForegroundWindow(intPtr);
    GetWindowRect(intPtr, ref rectangle);
    top = rectangle.Top;
    left = rectangle.Left;
    width = rectangle.Right - rectangle.Left;
    height = rectangle.Bottom - rectangle.Top;
    UIClass.ClickBar(this);
    }

    public void BringToFront()
    {
    IntPtr foregroundWindow = FindWindow("ApplicationFrameWindow", "Game Window");
    SetForegroundWindow(foregroundWindow);
    }

    public Bitmap Capture()
    {
    Bitmap bitmap = new Bitmap(Width, Height);
    Rectangle rectangle = new Rectangle(Left, Top, width, height);
    using (Graphics graphics = Graphics.FromImage(bitmap))
    {
    graphics.CopyFromScreen(new Point(rectangle.Left, rectangle.Top), Point.Empty, rectangle.Size);
    }
    return bitmap;
    }

    public void Capture(string path)
    {
    Bitmap bitmap = new Bitmap(Width, Height);
    Rectangle rectangle = new Rectangle(Left, Top, width, height);
    using (Graphics graphics = Graphics.FromImage(bitmap))
    {
    graphics.CopyFromScreen(new Point(rectangle.Left, rectangle.Top), Point.Empty, rectangle.Size);
    }
    bitmap.Save(Path.Combine(path, "UT" + DateTime.Now.Ticks.ToString() + ".jpg"));
    bitmap.Dispose();
    }
    }
    }



    This is what I tried to drill down to the child window

    public GameWindow(int titleHeight)
    {
    GetGameWindow();
    TitleHeight = titleHeight;
    }

    private void GetGameWindow()
    {
    Form1.Rect rectangle = default(Form1.Rect);
    IntPtr intPtr = FindWindow("HwndWrapper[Bluestacks.exe;;310d8add-fc43-4c3e-a64b-2cd5f6d0618c]", "BlueStacks");
    SecondBSWin = FindWindowEx(intPtr, IntPtr.Zero, "WindowsForms10.Window.8.app.0.34f5582_r6_ad1", "BlueStacks Android PluginAndroid");
    ThirdBSWin = FindWindowEx(SecondBSWin, IntPtr.Zero, "WindowsForms10.EDIT.app.0.34f5582_r6_ad1", null);
    ForthBSWin = FindWindowEx(ThirdBSWin, IntPtr.Zero, "BlueStacksApp", "_ctl.Window");
    SetForegroundWindow(ForthBSWin);
    GetWindowRect(ForthBSWin, ref rectangle);
    top = rectangle.Top;
    left = rectangle.Left;
    width = rectangle.Right - rectangle.Left;
    height = rectangle.Bottom - rectangle.Top;
    UIClass.ClickBar(this);
    }

    public void BringToFront()
    {
    IntPtr foregroundWindow = FindWindow("HwndWrapper[Bluestacks.exe;;edc30241-e5fe-4f1b-a9ae-8fcca64ba7b9]", "BlueStacks");
    SetForegroundWindow(foregroundWindow);
    SecondBSWin = FindWindowEx(foregroundWindow, IntPtr.Zero, "WindowsForms10.Window.8.app.0.34f5582_r6_ad1", "BlueStacks Android PluginAndroid");
    ThirdBSWin = FindWindowEx(SecondBSWin, IntPtr.Zero, "WindowsForms10.EDIT.app.0.34f5582_r6_ad1", null);
    ForthBSWin = FindWindowEx(ThirdBSWin, IntPtr.Zero, "BlueStacksApp", "_ctl.Window");

    }

    public Bitmap Capture()
    {
    Bitmap bitmap = new Bitmap(Width, Height);
    Rectangle rectangle = new Rectangle(Left, Top, width, height);
    using (Graphics graphics = Graphics.FromImage(bitmap))
    {
    graphics.CopyFromScreen(new Point(rectangle.Left, rectangle.Top), Point.Empty, rectangle.Size);
    }
    return bitmap;
    }

    public void Capture(string path)
    {
    Bitmap bitmap = new Bitmap(Width, Height);
    Rectangle rectangle = new Rectangle(Left, Top, width, height);
    using (Graphics graphics = Graphics.FromImage(bitmap))
    {
    graphics.CopyFromScreen(new Point(rectangle.Left, rectangle.Top), Point.Empty, rectangle.Size);
    }
    bitmap.Save(Path.Combine(path, "UT" + DateTime.Now.Ticks.ToString() + ".jpg"));
    bitmap.Dispose();
    }
    }
    }
    The entire project works fine on the native Windows version, all I have done so far is adjust the program to use the BlueStacks window which it does. I can set the BlueStacks emulator to use either OpenGL or DircetX as it's "Engine" it makes no difference at all. I have also tried to use the MeMu emulator but I get the same results.

    When I check the pixel color at the x, y where I want to interact with the game it shows as black instead of the actual color green. I found many other questions that were getting black screens returned from similar operations, not sure if it's the same problem here.

    I would appreciate any suggestions as I have searched a great deal and not found an answer yet.

    Here is the window in Spy++

    SpyPlus.JPG

    Trying to take a screen capture of a game running in BlueStacks using C#

Similar Threads

  1. Replies: 0
    Last Post: 12-18-2013, 05:46 PM
  2. [Selling] STEAM KEYS - Couple of THQ Games bought in bundle
    By Kabraxiss in forum General Trading Buy Sell Trade
    Replies: 2
    Last Post: 01-20-2013, 10:10 PM
  3. How to get into the business of reselling games?
    By declensions in forum Community Chat
    Replies: 0
    Last Post: 09-07-2012, 09:49 PM
  4. [Help] Trying to look for this type of server
    By mchugh in forum World of Warcraft Emulator Servers
    Replies: 3
    Last Post: 03-06-2008, 12:23 PM
  5. query to take the skill requierment of mounts
    By *TraPStaR* in forum World of Warcraft Emulator Servers
    Replies: 2
    Last Post: 11-26-2007, 12:38 PM
All times are GMT -5. The time now is 04:06 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search