Comments (4)
No, right now you need to capture the entire monitor and copy out the portion you're interested in using CopySubresourceRegion.
from windows.ui.composition-win32-samples.
do you have a short code snippet for this?
from windows.ui.composition-win32-samples.
I don't have a self-contained snippet to share with you, but the idea is straight forward. Let's say that you have two textures, texture A comes from the capture API and texture B is the texture that will receive the pixels you're interested in. You would call CopySubresourceRegion
on the ID3D11DeviceContext
and supply the area of interest from texture A and specify that it will be copied into texture B.
robmikh/GifSnip
does this very thing to copy a portion of the screen to an output texture used to encode a gif.
from windows.ui.composition-win32-samples.
Here are some snippets of the relevant code I used. It's just the relevant lines of my code, It won't run.
Member variable:
D3D11_BOX m_roiWindow; //Region of interest rect
ID3D11Texture2D* m_stagingTexture= NULL;
//Set Function
SetROIWindow(float x, float y, float width, float height) {
m_roiWindow.left = max(0.0f,x);
m_roiWindow.top = max(0.0f,y);
m_roiWindow.right = m_roiWindow.left + width;
m_roiWindow.bottom = m_roiWindow.top + height;
}
//Inside OnFrameArrived:
auto frame = sender.TryGetNextFrame();
auto swapChainResizedToFrame = TryResizeSwapChain(frame);
auto surfaceTexture = GetDXGIInterfaceFromObject<ID3D11Texture2D>(frame.Surface());
m_d3dContext->CopySubresourceRegion(m_stagingTexture, 0, 0, 0, 0, surfaceTexture.get(), 0, &m_roiWindow);
D3D11_MAPPED_SUBRESOURCE mappedSubResource;
auto hr = m_d3dContext->Map(m_stagingTexture, 0, D3D11_MAP_READ, 0, &mappedSubResource);
<Use mappedSubResource.pData for something>
//Unmap
m_d3dContext->Unmap(m_stagingTexture, 0);
frame.Close();
An issue I had is that I had to make sure the width and height of the region is 32bit aligned, but that is probably because I use the data in an openGL texture. You might not have that issue.
from windows.ui.composition-win32-samples.
Related Issues (20)
- Some samples use `WindowsRuntimeMarshal` class, that is no longer available in .NET 5+ HOT 4
- Cannot use IGraphicsCaptureItemInterop::CreateForWindow with electron apps HOT 6
- This repo is missing important files HOT 4
- How to capture Windows10/11 Virtual Desktop via Windows.Graphics.Capture ? HOT 2
- Accessing screen capture image bytes with MapFlags.DoNotWait for better CPU usage HOT 3
- Can I do successive captures on two different windows HOT 8
- ScreenCapture Sample - write capture stream to disk mp4? HOT 5
- Memory Leak? HOT 5
- BSODs on 4 separate Hard Drives HOT 3
- Multiple screen captures in a loop cause explorer.exe and native Windows app to lag? HOT 11
- Capture OnFrame Callback very slow on Win11 23H2 HOT 7
- access_denied in CreateForMonitor in some cases HOT 5
- Cannot catch errors in CreateCaptureItemForWindow HOT 3
- WGC CaptureFrame returns wrong SystemRelativeTime in window capture mode HOT 2
- Cursor may become invisible when recording some fullscreen games using WGC HOT 6
- Frame has issue after change window state (maximize from normal/ normal from maximize/ ...) HOT 1
- ScreenCaptureforHWND sample leaks handles leading to "Out of memory" crash HOT 1
- ScreenCaptureforHWND sample main thread hang HOT 2
- ScreenCaptureforHWND: How to get the byte data of the captured frame? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from windows.ui.composition-win32-samples.