-1

これはCreateDIBSectionに関する拡張質問です。

Direct3D を使用して描画した同じ画像の bitMap ビット値を取得するために使用し、Direct3D レンダリングの一貫性を検証しました。つまり、プログラムを実行するたびに同じ bitMap ビット値を取得する限り (同じ画像を描画する)、次に、Direct3D レンダリングが成功したと見なします。

ただし、奇妙なことに、プログラムを実行して最初の 4 回 (同じイメージを描画する)、5 回目以降は、(以下のコードに示すように「イメージ」から) 同じ bitMap ビット値しか取得できないことです。 、bitMap ビット値の結果がわずかに変化し始め (少数のバイトのみが変更され、残りのほとんどのバイトは同じまま)、最初の 4 回と同じ bitMap ビット値が返されることはありません。

しかし、コンピューターを再起動してプログラムを再度実行すると、同じパターンが返されます。プログラムを実行して最初の 4 回で取得したビットマップのビット値は、最初の試行とまったく同じですが、次のようになります。実行すると、異なる bitMap ビット値になります。

私が考えることができる2つの考えられる理由:

  1. GPU によるレンダリングには若干の不一致があり、GPU に何らかの欠陥が含まれている可能性がありますが、私は GPU の専門家ではないため、このように結論付ける自信はありません。

  2. CreateDIBSection が独自にメモリ割り当てを処理することはわかっていましたが、DeleteObject の呼び出し後にメモリが適切に消去されず、bitMap ビット値の一部のビットに影響を与える可能性はありますか? (このディスカッションでメモリを解放する手順に従いましたが、同じイメージの一貫した bitMap ビット値を取得するのには役立ちません。)

質問: 同じ画像から取得するときに、一貫した bitMap ビット値を毎回取得するにはどうすればよいですか (それは可能ですか?)。

ありがとう。

コード:

#include <Windows.h>
#include <cstdint>
HWND m_hwnd;

void GetBitMapInfo(const int& x_Coordinate, const int& y_Coordinate, const int& iWidth, const int& iHeight)
{

DWORD imageSize = iWidth * iHeight * 4;

// Get the display window
HDC displayWindow = GetDC(m_hwnd);
HDC hdc = CreateCompatibleDC(displayWindow);

// Fill in the Bitmap information
BITMAPINFO bmpInfo;
ZeroMemory(&bmpInfo, sizeof(BITMAPINFO));
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biWidth = iWidth;
bmpInfo.bmiHeader.biHeight = iHeight;
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biBitCount = 32;
bmpInfo.bmiHeader.biCompression = BI_RGB;
bmpInfo.bmiHeader.biSizeImage = 0;
bmpInfo.bmiHeader.biClrUsed = 0;
bmpInfo.bmiHeader.biClrImportant = 0;


// Create the storage for the pixel information
uint8_t* image = nullptr;

// Populate the storage with the BMP pixel information
HBITMAP hBitmap = CreateDIBSection(hdc, &bmpInfo, DIB_RGB_COLORS, (void**)(&image), nullptr, NULL);

HGDIOBJ save = SelectObject(hdc, hBitmap);
BitBlt(hdc, x_Coordinate, y_Coordinate, iWidth, iHeight, displayWindow, 0, 0, SRCCOPY);


DeleteObject(SelectObject(hdc, save));
DeleteDC(hdc);
DeleteDC(displayWindow);
DeleteObject(hBitmap);

return;
}

int main()
{
    GetBitMapInfo(0, 0, 1920, 1080);

    return 0;
}
4

1 に答える 1