30QT_WARNING_DISABLE_DEPRECATED
32 QWindowsDirect2DContext::instance()->d2dFactory()->GetDesktopDpi(&dpiX, &dpiY);
35 return D2D1::BitmapProperties1(
36 D2D1_BITMAP_OPTIONS_TARGET,
37 D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM,
38 D2D1_ALPHA_MODE_PREMULTIPLIED),
43 bool resize(
int width,
int height,
const void *data =
nullptr,
int pitch = 0)
45 deviceContext->get()->SetTarget(
nullptr);
49 UINT32(width), UINT32(height)
52 HRESULT hr = deviceContext->get()->CreateBitmap(size, data, UINT32(pitch),
54 bitmap.ReleaseAndGetAddressOf());
56 deviceContext->get()->SetTarget(bitmap.Get());
58 qWarning(
"%s: Could not create bitmap: %#lx",
__FUNCTION__, hr);
68 ComPtr<ID2D1Bitmap1> mappingCopy;
71 D2D1_SIZE_U size = bitmap->GetPixelSize();
73 D2D1_BITMAP_PROPERTIES1 properties = bitmapProperties();
74 properties.bitmapOptions = D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_CPU_READ;
76 hr = deviceContext->get()->CreateBitmap(size,
nullptr, 0,
77 properties, &mappingCopy);
79 qWarning(
"%s: Could not create bitmap: %#lx",
__FUNCTION__, hr);
83 hr = mappingCopy->CopyFromBitmap(
nullptr, bitmap.Get(),
nullptr);
85 qWarning(
"%s: Could not copy from bitmap: %#lx",
__FUNCTION__, hr);
89 D2D1_MAPPED_RECT mappedRect;
90 hr = mappingCopy->Map(D2D1_MAP_OPTIONS_READ, &mappedRect);
92 qWarning(
"%s: Could not map: %#lx",
__FUNCTION__, hr);
96 return QImage(
static_cast<
const uchar *>(mappedRect.bits),
97 int(size.width),
int(size.height),
int(mappedRect.pitch),
98 QImage::Format_ARGB32_Premultiplied).copy(rect);