My goal is to capture a screen using DirectX in Java . I found the project fully detailed and explained here in C #.
Unfortunately, I have no knowledge in C sharp. I donβt know if I can ask here to rewrite the code above mentioned from C # to Java for those who process both languages, but I think that the end result will be of interest to many people.
In any case, I thank those who would be kind to help me with this. Even if I have never tried, I know that C # β Java conversion software (or any other language) is not recommended, explaining my rewriting question .
Please check out the code below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SlimDX.Direct3D9;
namespace KMPP
{
public class DxScreenCapture
{
Device d;
public DxScreenCapture()
{
PresentParameters present_params = new PresentParameters();
present_params.Windowed = true;
present_params.SwapEffect = SwapEffect.Discard;
d = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, present_params);
}
public Surface CaptureScreen()
{
Surface s = Surface.CreateOffscreenPlain(d, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, Format.A8R8G8B8, Pool.Scratch);
d.GetFrontBufferData(0, s);
return s;
}
}
}
PS: Since Surface s is a DirectX type here, I would be interested to convert it to PNG then.
source
share