Code Monkey home page Code Monkey logo

Comments (4)

robmikh avatar robmikh commented on June 2, 2024

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.

michiproep avatar michiproep commented on June 2, 2024

do you have a short code snippet for this?

from windows.ui.composition-win32-samples.

robmikh avatar robmikh commented on June 2, 2024

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.

MartinClementson avatar MartinClementson commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.