DirectX 11 ClearRenderTargetView 恢复透明缓冲区?

2024-04-24

我正在尝试创建一个使用 directx 进行绘制的窗口opaque上面的内容透明的视图(即桌面显示出来)。使用 DirectX11,我尝试执行以下操作,但它并没有使背景透明。事实上,我输入的任何不透明度值都会给出完全相同的结果。

我在做什么:

float color[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
deviceContext->ClearRenderTargetView(backBuffer, color);

工作重现代码(main.cpp):

#include <Windows.h>
#include <windowsx.h>
#pragma comment (lib, "Winmm.lib")

#include <d3d11.h>
#pragma comment (lib, "d3d11.lib")
#include <d3dcompiler.h>
#pragma comment(lib, "D3DCompiler.lib")

#include <dwmapi.h>
#pragma comment (lib, "Dwmapi.lib")


// Globals
IDXGISwapChain *swapChain;
ID3D11Device *device;
ID3D11DeviceContext *deviceContext;
ID3D11RenderTargetView *backBuffer;
ID3D11InputLayout *inputLayout;            // the pointer to the input layout
ID3D11VertexShader *vertexShader;               // the pointer to the vertex shader
ID3D11PixelShader *pixelShader;                // the pointer to the pixel shader
ID3D11Buffer *vertexBuffer;                // the pointer to the vertex buffer

void InitializeDirectX(HWND hWnd);
void LoadTriangle();

struct Vertex {
    float x, y, z;
    float color[4];
};

// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_DESTROY:
    {
                       // close the application entirely
                       PostQuitMessage(0);
                       return 0;
    }
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
}

// Globals
const LPCWSTR ClassName = L"className";


// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
{
    // the handle for the window, filled by a function
    HWND hWnd;
    // this struct holds information for the window class
    WNDCLASSEX wc;

    // Pick out window size
    int windowHeight = 400;
    int windowWidth = 400;

    // clear out the window class for use
    ZeroMemory(&wc, sizeof(WNDCLASSEX));

    // fill in the struct with the needed information
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = ClassName;

    // register the window class
    RegisterClassEx(&wc);

    // Window style
    DWORD exStyle = WS_EX_LAYERED | WS_EX_TOPMOST;
    DWORD style = WS_POPUP;

    // create the window and use the result as the handle
    hWnd = CreateWindowEx(
        exStyle,        // extended styles
        ClassName,    // name of the window class
        L"TestOverlay",   // title of the window
        style,    // window style
        0,    // x-position of the window
        0,    // y-position of the window
        400,    // width of the window
        400,    // height of the window
        NULL,    // we have no parent window, NULL
        NULL,    // we aren't using menus, NULL
        hInstance,    // application handle
        NULL);    // used with multiple windows, NULL

    // display the window on the screen
    ShowWindow(hWnd, nCmdShow);

    SetWindowPos(hWnd,
        HWND_TOPMOST,
        0, 0,
        windowWidth, windowHeight,
        SWP_SHOWWINDOW);

    // Show the window
    ShowWindow(hWnd, SW_SHOWDEFAULT);
    UpdateWindow(hWnd);

    // Make the window transparent
    SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_LAYERED);
    SetLayeredWindowAttributes(hWnd, RGB(0, 0, 0), 255, LWA_ALPHA | LWA_COLORKEY);

    // NOTE: If I uncomment DwmExtendFrameIntoClientArea then it becomes transparent, otherwise its a black screen
    MARGINS dwmMargin = { -1 };
    //DwmExtendFrameIntoClientArea(hWnd, &dwmMargin);

    // DirectX
    InitializeDirectX(hWnd);
    LoadTriangle();

    // enter the main loop:
    MSG msg;
    BOOL gotMessage;
    while (TRUE)
    {
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);

            if (msg.message == WM_QUIT)
                break;

            // DirectX stuff
            float color[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
            deviceContext->ClearRenderTargetView(backBuffer, color);

            // Draw triangle
            UINT stride = sizeof(Vertex);
            UINT offset = 0;
            deviceContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset);
            deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
            deviceContext->Draw(3, 0);

            swapChain->Present(0, 0);

        }
    }

    return msg.wParam;
}


void InitializeDirectX(HWND hWnd)
{
    // create a struct to hold information about the swap chain
    DXGI_SWAP_CHAIN_DESC scd;

    // clear out the struct for use
    ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));

    // fill the swap chain description struct
    scd.BufferCount = 1;                                    // one back buffer
    scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;     // use 32-bit color
    scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;      // how swap chain is to be used
    scd.OutputWindow = hWnd;                                // the window to be used
    scd.SampleDesc.Count = 4;                               // how many multisamples
    scd.Windowed = TRUE;                                    // windowed/full-screen mode

    // create a device, device context and swap chain using the information in the scd struct
    D3D11CreateDeviceAndSwapChain(NULL,
        D3D_DRIVER_TYPE_HARDWARE,
        NULL,
        NULL,
        NULL,
        NULL,
        D3D11_SDK_VERSION,
        &scd,
        &swapChain,
        &device,
        NULL,
        &deviceContext);


    // get the address of the back buffer
    ID3D11Texture2D *pBackBuffer;
    swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);

    // use the back buffer address to create the render target
    device->CreateRenderTargetView(pBackBuffer, NULL, &backBuffer);
    pBackBuffer->Release();

    // set the render target as the back buffer
    deviceContext->OMSetRenderTargets(1, &backBuffer, NULL);

    // Set the viewport size
    RECT cRect;
    GetClientRect(hWnd, &cRect);

    D3D11_VIEWPORT viewport;
    ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));

    viewport.TopLeftX = 0;
    viewport.TopLeftY = 0;
    viewport.Width = cRect.right - cRect.left;
    viewport.Height = cRect.bottom - cRect.top;

    deviceContext->RSSetViewports(1, &viewport);


    // Initialize pipeline stuff
    ID3D10Blob *VS, *PS;

    // compile shader
    D3DCompileFromFile(L"shaders.shader", 0, 0, "VShader", "vs_4_0", 0, 0, &VS, 0);
    D3DCompileFromFile(L"shaders.shader", 0, 0, "PShader", "ps_4_0", 0, 0, &PS, 0);

    // encapsulate both shaders into shader objects
    device->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &vertexShader);
    device->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pixelShader);

    deviceContext->VSSetShader(vertexShader, 0, 0);
    deviceContext->PSSetShader(pixelShader, 0, 0);

    // create input layout object
    D3D11_INPUT_ELEMENT_DESC ied[] =
    {
        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
        { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    };

    device->CreateInputLayout(ied, 2, VS->GetBufferPointer(), VS->GetBufferSize(), &inputLayout);
    deviceContext->IASetInputLayout(inputLayout);

}


void LoadTriangle()
{
    // create a triangle using the VERTEX struct
    Vertex OurVertices[] =
    {
    { 0.0f, 0.5f, 0.0f, { 1.0f, 0.0f, 0.0f, 1.0f } },
    { 0.45f, -0.5, 0.0f, { 0.0f, 1.0f, 0.0f, 1.0f } },
    { -0.45f, -0.5f, 0.0f, { 0.0f, 0.0f, 1.0f, 1.0f } }
    };


    // create the vertex buffer
    D3D11_BUFFER_DESC bd;
    ZeroMemory(&bd, sizeof(bd));

    bd.Usage = D3D11_USAGE_DYNAMIC;                // write access access by CPU and GPU
    bd.ByteWidth = sizeof(Vertex)* 3;             // size is the VERTEX struct * 3
    bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;       // use as a vertex buffer
    bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;    // allow CPU to write in buffer

    device->CreateBuffer(&bd, NULL, &vertexBuffer);       // create the buffer


    // copy the vertices into the buffer
    D3D11_MAPPED_SUBRESOURCE ms;
    deviceContext->Map(vertexBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);    // map the buffer
    memcpy(ms.pData, OurVertices, sizeof(OurVertices));                 // copy the data
    deviceContext->Unmap(vertexBuffer, NULL);                                      // unmap the buffer
}

着色器文件(shaders.shader):

struct VOut
{
    float4 position : SV_POSITION;
    float4 color : COLOR;
};

VOut VShader(float4 position : POSITION, float4 color : COLOR)
{
    VOut output;

    output.position = position;
    output.color = color;

    return output;
}

float4 PShader(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET
{
    return color;
}

如果您取消注释第 119 行的 DwmExtendFrameIntoClientArea 调用,那么它将获得我正在寻找的效果。我想知道是否有一种方法可以在不使用 dwm 的情况下获得相同的效果(出于我不会详细讨论的原因)。

有任何想法吗?

编辑:添加了工作示例的完整源代码。发现如果我调用 DwmExtendFrameIntoClientArea,那么我就会得到我想要的效果。但我仍然想知道是否可以在不使用 dwm api 的情况下做到这一点。


仅使用 DirectX 无法使窗口透明,以下代码仅将背景颜色清除为黑色。

float color[4] = { 0.0f, 0.0f, 0.0f, 0.0f };

要实现窗口的透明效果,你需要涉及一些win32的东西,SetLayeredWindowAttributes是你的选择。

// Show the window
ShowWindow( hWnd, SW_SHOWDEFAULT );
UpdateWindow( hWnd );

SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_LAYERED) ;
SetLayeredWindowAttributes(hWnd, RGB(0, 0, 0), 100, LWA_ALPHA);

UPDATE:

可行的代码什么也不绘制,只是使窗口以绿色透明。

#include <Windows.h>
#include <windowsx.h>
#pragma comment (lib, "Winmm.lib")

#include <d3d11.h>
#pragma comment (lib, "d3d11.lib")
#include <d3dcompiler.h>
#pragma comment(lib, "D3DCompiler.lib")

#include <dwmapi.h>
#pragma comment (lib, "Dwmapi.lib")


// Globals
IDXGISwapChain *swapChain;
ID3D11Device *device;
ID3D11DeviceContext *deviceContext;
ID3D11RenderTargetView *backBuffer;

void InitializeDirectX(HWND hWnd);

// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_DESTROY:
        {
            // close the application entirely
            PostQuitMessage(0);
            return 0;
        }
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
}

// Globals
const LPCWSTR ClassName = L"className";


// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    WNDCLASSEX wc;
    ZeroMemory(&wc, sizeof(WNDCLASSEX));

    // fill in the struct with the needed information
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = ClassName;

    // register the window class
    RegisterClassEx(&wc);

    // create the window and use the result as the handle
    HWND hWnd = CreateWindowEx(
        NULL,        // extended styles
        ClassName,    // name of the window class
        L"TestOverlay",   // title of the window
        WS_OVERLAPPEDWINDOW,    // window style
        0,    // x-position of the window
        0,    // y-position of the window
        400,    // width of the window
        400,    // height of the window
        NULL,    // we have no parent window, NULL
        NULL,    // we aren't using menus, NULL
        hInstance,    // application handle
        NULL);    // used with multiple windows, NULL

    // display the window on the screen
    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);

    // Make the window transparent
    SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_LAYERED) ;
    SetLayeredWindowAttributes(hWnd, RGB(0, 0, 0), 128, LWA_ALPHA);

    // DirectX
    InitializeDirectX(hWnd);

    // enter the main loop:
    MSG msg;
    BOOL gotMessage;
    while (TRUE)
    {
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);

            if (msg.message == WM_QUIT)
                break;

            // DirectX stuff
            float color[4] = { 0.0f, 1.0f, 0.0f, 0.0f };
            deviceContext->ClearRenderTargetView(backBuffer, color);
            swapChain->Present(0, 0);
        }
    }

    return msg.wParam;
}


void InitializeDirectX(HWND hWnd)
{
    // create a struct to hold information about the swap chain
    DXGI_SWAP_CHAIN_DESC scd;

    // clear out the struct for use
    ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));

    // fill the swap chain description struct
    scd.BufferCount = 1;                                    // one back buffer
    scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;     // use 32-bit color
    scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;      // how swap chain is to be used
    scd.OutputWindow = hWnd;                                // the window to be used
    scd.SampleDesc.Count = 4;                               // how many multisamples
    scd.Windowed = TRUE;                                    // windowed/full-screen mode

    // create a device, device context and swap chain using the information in the scd struct
    D3D11CreateDeviceAndSwapChain(NULL,
        D3D_DRIVER_TYPE_HARDWARE,
        NULL,
        NULL,
        NULL,
        NULL,
        D3D11_SDK_VERSION,
        &scd,
        &swapChain,
        &device,
        NULL,
        &deviceContext);


    // get the address of the back buffer
    ID3D11Texture2D *pBackBuffer;
    swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);

    // use the back buffer address to create the render target
    device->CreateRenderTargetView(pBackBuffer, NULL, &backBuffer);
    pBackBuffer->Release();

    // set the render target as the back buffer
    deviceContext->OMSetRenderTargets(1, &backBuffer, NULL);

    // Set the viewport size
    RECT cRect;
    GetClientRect(hWnd, &cRect);

    D3D11_VIEWPORT viewport;
    ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));

    viewport.TopLeftX = 0;
    viewport.TopLeftY = 0;
    viewport.Width = cRect.right - cRect.left;
    viewport.Height = cRect.bottom - cRect.top;

    deviceContext->RSSetViewports(1, &viewport);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

DirectX 11 ClearRenderTargetView 恢复透明缓冲区? 的相关文章

  • 如何使用 MVVM 更新 WPF 中编辑的数据? [复制]

    这个问题在这里已经有答案了 我正在为聊天应用程序构建 UI 设计 在尝试更新所选联系人的消息时遇到问题 选择现有联系人 选择编辑选项 然后编辑其属性 例如用户名和图像 后 唯一进行的更改是联系人的用户名和图像 我仍然想更改 MessageM
  • 使用 OpenGL 着色器进行数学计算 (C++)

    我有一个矩阵 例如 100x100 尺寸 我需要对每个元素进行计算 matrix i j tt 8 5例如 我有一个巨大的矩阵 我想使用 OpenGL 着色器来实现该算法 我想使用着色器 例如 uniform float val unifo
  • 用户控件内所有控件均为空

    我有一个 UserControl 它使用 UserControl 以及其他控件 In the ascx文件我有以下代码
  • 静态类变量与外部变量相同,只是具有类作用域吗?

    在我看来 静态类变量与外部变量相同 因为你只需要declare它在static int x extern int x语句 并在其他地方实际定义它 通常在 cpp 文件中 静态类变量 h file class Foo static int x
  • 无法从 Web api POST 读取正文数据

    我正在尝试从新的 Asp Net Web Api 中的请求中提取一些数据 我有一个像这样的处理程序设置 public class MyTestHandler DelegatingHandler protected override Syst
  • 从 future 中检索值时的 SIGABRT

    我在使用 C 11 future 时遇到问题 当我打电话时wait or get 关于返回的未来std async 程序接收从mutex标头 可能是什么问题呢 如何修复它 我在 Linux 上使用 g 4 6 将以下代码粘贴到 ideone
  • 如何在 Asp.net Gridview 列中添加复选框单击事件

    我在 asp 中有一个 gridview 其中我添加了第一列作为复选框列 现在我想选择此列并获取该行的 id 值 但我不知道该怎么做 这是我的 Aspx 代码
  • 如何使用 python 操作系统更改驱动器?

    我正在尝试更改当前目录C to Y 我试过 import os os chdir Y 但我不断收到错误消息 提示无法找到驱动器 本质上我正在寻找相当于 cd d cmd 中的命令 你确定吗Y 确实是有效的驱动器号吗 Try os chdir
  • 更改 IdentityServer4 实体框架表名称

    我正在尝试更改由 IdentityServer4 的 PersistedGrantDb 和 ConfigurationDb 创建的默认表名称 并让实体框架生成正确的 SQL 例如 而不是使用实体IdentityServer4 EntityF
  • 错误左值需要作为赋值C++的左操作数

    整个程序基本上只允许用户移动光标 如果用户位于给定的坐标范围 2 2 内 则允许用户键入输入 我刚刚提供了一些我认为足以解决问题的代码 我不知道是什么导致了这个问题 你能解释一下为什么会发生吗 void goToXY int int 创建一
  • 不兼容的类型 - 是因为数组已经是指针吗?

    在下面的代码中 我创建一个基于书籍结构的对象 并让它保存多个 书籍 我设置的是一个数组 即定义 启动的对象 然而 每当我去测试我对指针的了解 实践有帮助 并尝试创建一个指向创建的对象的指针时 它都会给我错误 C Users Justin D
  • 如何使用收益返回和递归获得字母的每个组合?

    我有几个像这样的字符串列表 可能有几十个列表 1 A B C 2 1 2 3 3 D E F 这三个仅作为示例 用户可以从几十个具有不同数量元素的类似列表中进行选择 再举个例子 这对于用户来说也是一个完全有效的选择 25 empty 4 1
  • 相当于 C# 中 Java 的“ByteBuffer.putType()”

    我正在尝试通过从 Java 移植代码来格式化 C 中的字节数组 在 Java 中 使用方法 buf putInt value buf putShort buf putDouble 等等 但我不知道如何将其移植到 C 我尝试过 MemoryS
  • 从 C 线程调用 Python 代码

    我对从 C 或 C 线程调用 Python 代码时如何确保线程安全感到非常困惑 The Python 文档 http docs python org c api init html non python created threads似乎是
  • 纯虚函数可能没有内联定义。为什么?

    纯虚函数是那些虚函数并且具有纯说明符 0 第 10 4 条第 2 款C 03 的内容告诉我们什么是抽象类 顺便说一句 如下 注意 函数声明不能 同时提供纯说明符和定义 尾注 示例 struct C virtual void f 0 ill
  • ASP.NET Core Razor Page 多路径路由

    我正在使用 ASP NET Core 2 0 Razor Pages 不是 MVC 构建系统 但在为页面添加多个路由时遇到问题 例如 所有页面都应该能够通过 abc com language 访问segment shop mypage 或
  • C++ [Windows] 可执行文件所在文件夹的路径[重复]

    这个问题在这里已经有答案了 我需要访问一些文件fstream在我的 Windows 上的 C 应用程序中 这些文件都位于我的exe文件所在文件夹的子文件夹中 获取当前可执行文件的文件夹路径的最简单且更重要的 最安全的方法是什么 Use 获取
  • c# 模拟 IFormFile CopyToAsync() 方法

    我正在对一个异步函数进行单元测试 该函数将 IFormFile 列表转换为我自己的任意数据库文件类列表 将文件数据转换为字节数组的方法是 internal async Task
  • 新的 .NET 6 控制台模板中的 C# 函数重载不起作用

    我在尝试重载该函数时遇到错误Print object in the 新的 NET 6 C 控制台应用程序模板 https learn microsoft com en us dotnet core tutorials top level t
  • FindAsync 很慢,但是延迟加载很快

    在我的代码中 我曾经使用加载相关实体await FindAsync 希望我能更好地遵守 C 异步指南 var activeTemplate await exec DbContext FormTemplates FindAsync exec

随机推荐

  • 在 Haskell 中的列表末尾添加一个元素

    我是 Haskell 的初学者 我正在尝试在列表末尾添加一个元素 我输入一个像 1 2 3 4 这样的列表和一个数字 10 我想要一个像这样的输出 1 2 3 4 10 My code func a a func a x xs x func
  • 在 View 中使用 Zend_Acl 来显示/隐藏部分视图的方法是什么

    我想知道使用 Zend Acl 来显示 隐藏部分视图的方法是什么 我想我会的 创建一个Controller Plugin 传递登录用户 acl来查看 this gt view gt loggedInUser Zend Auth getIde
  • 随机数独生成

    我正在编写一个函数 该函数应该为模拟项目生成随机数独谜题 该函数将要生成的单元格数量作为参数 然后生成单元格索引和要放入这些单元格中的数字 我在生成单元格索引时遇到问题 我不是编程专家 我找不到一个好的例程来生成索引并检查是否两次或更多次是
  • HTTP 500 响应通过 RawXmlMessage.aspx 通过仪表板将 CCTray 连接到 CC.NET 服务器

    我正在使用 CC NET 1 6 服务器及其相应的 CCTray 通过远程处理轻松连接 但需要更改为通过 HTTP 使用仪表板连接 以便我可以开始将 URL 外包给开发人员 将我的仪表板 URL 放入 CCTray 中 http local
  • 有没有办法在 Shadow-DOM 中访问 CSS 中的 HTML 标签属性?

    我正在使用 StencilJS 创建一个自定义组件 当用户使用键盘或鼠标导航到该组件时 我必须对轮廓进行一些更改 我的组件正在使用 ShadowDOM 我想从 CSS 访问 HTML 标签属性 标签的属性是通过 What input 生成的
  • 从多个数据帧中提取公共行的子集

    我有多个数据框 如下所述 每行都有唯一的 id 我试图找到公共行并创建一个至少出现在两个数据框中的新数据框 示例 Id 2 的行出现在所有三个数据框中 类似地 df1 和 df3 中存在 Id 3 的行 我想创建一个循环 可以找到公共行并创
  • sqlite通过命令行导入csv时出错

    sqlite3 test sql SQLite version 3 6 12 Enter help for instructions Enter SQL statements terminated with a sqlite gt crea
  • 如何从后台服务更新 Android Activity 中的信息

    我正在尝试创建一个简单的Android应用程序 它有一个ActivityList信息 当应用程序启动时 我计划启动一个服务 它将不断计算数据 它会改变 并且我希望ActivityList与服务在应用程序生命周期内计算的数据 如何将我的活动设
  • 为什么 Groovy/Grape 不能解析来自 Maven Central 的工件?

    通过全新下载的 Groovy 2 1 9 我创建了 Test Groovy Grab commons io commons io 1 2 import org apache commons io CopyUtils println Reso
  • 与受保护的内部成员的可访问性不一致

    尝试在公共类中创建受保护内部类的受保护内部成员会导致以下问题 可访问性不一致 字段类型 what Class1 ProtectedInternalClass 比字段更难访问 what Class1 SomeDataProvider data
  • 安装 PyQt

    我正在尝试在我的 mac 上安装 PyQt 以便可以安装 python Ghost 我已经安装了Qt和SIP 我已经下载了 PyQt 但是当我运行时 python configure ng py 我收到以下错误 Error Use the
  • 我可以在 reStructuredText 中使用内联原始 LaTeX

    我正在尝试将 LaTeX 变量嵌入到一些 reStructuredText 中 我知道 raw 指令 但我希望将其嵌入到文本段落中 具体来说 我希望从模板考试文档中复制 numquestions 和 numpoints 变量 我尝试过使用
  • yaml.parser.ParserError:解析块映射时

    ERROR yaml parser ParserError while parsing a block mapping in tmp statelesscs compose yml line 1 column 1 expected
  • github 存储库的本地缓存?

    我们使用 github 来管理我们的大量软件环境 我敢打赌 像许多其他组织一样 该存储库的绝大多数流量来自我们的办公室 考虑到这一点 有没有一种方法可以构建给定 github 存储库的本地缓存 但仍然具有云版本的保护 我在缓存代理服务器的模
  • 设置 stats_flutter 时间序列图表中时间标签的格式以包含 hh:mm:ss

    是否可以格式化charts flutter时间序列图表的x轴上的标签以进行显示hh mm ss 这个答案 https stackoverflow com a 51138909 1954993解释了如何格式化代码以显示月份和日期 但我需要显示
  • 快速加速平均值和标准差

    我正在研究 Accelerate 以计算 Swift 中数组的平均值和标准差 我可以做到这一点 如何计算标准差 let rr Double 18 0 21 0 41 0 42 0 48 0 50 0 55 0 90 0 var mn Dou
  • 除了不可变值对象之外,什么时候应该重写 equals() ?

    很明显equals 而且当然hashCode 在处理不可变值对象时很有价值 映射键 需要在包含它们的对象之间进行比较的强类型字段值等 但除了值对象之外 您有多少可能真正拥有两个独立构造的实例并希望它们成为equal 我很难想象一个现实的场景
  • 我可以使用在 DispatcherServlet Context 中声明的 Hibernate Session Factory 而不是 hibernate.cfg.xml 吗?

    在我之前的 Spring MVC 项目中 我使用 Hibernate 作为 JPA 的提供者 我不必创建hibernate cfg xml文件 因为我已经在 Spring DispatcherServlet 上下文文件中声明了 Hibern
  • 为什么 JSON 应该有一个 status 属性

    我偶然发现了一种相当普遍的做法 我什至找到了一个为其命名的网页 但我忘记了名称 并且无法再在谷歌上找到该页面 实践中 来自 REST 服务的每个 JSON 响应都应具有以下结构 status ok data 或者在错误情况下 status
  • DirectX 11 ClearRenderTargetView 恢复透明缓冲区?

    我正在尝试创建一个使用 directx 进行绘制的窗口opaque上面的内容透明的视图 即桌面显示出来 使用 DirectX11 我尝试执行以下操作 但它并没有使背景透明 事实上 我输入的任何不透明度值都会给出完全相同的结果 我在做什么 f