44 bool resize(
int width,
int height,
const void *data =
nullptr,
int pitch = 0)
46 deviceContext->get()->SetTarget(
nullptr);
50 UINT32(width), UINT32(height)
53 HRESULT hr = deviceContext->get()->CreateBitmap(size, data, UINT32(pitch),
55 bitmap.ReleaseAndGetAddressOf());
57 deviceContext->get()->SetTarget(bitmap.Get());
59 qWarning(
"%s: Could not create bitmap: %#lx",
__FUNCTION__, hr);
69 ComPtr<ID2D1Bitmap1> mappingCopy;
72 D2D1_SIZE_U size = bitmap->GetPixelSize();
74 D2D1_BITMAP_PROPERTIES1 properties = bitmapProperties();
75 properties.bitmapOptions = D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_CPU_READ;
77 hr = deviceContext->get()->CreateBitmap(size,
nullptr, 0,
78 properties, &mappingCopy);
80 qWarning(
"%s: Could not create bitmap: %#lx",
__FUNCTION__, hr);
84 hr = mappingCopy->CopyFromBitmap(
nullptr, bitmap.Get(),
nullptr);
86 qWarning(
"%s: Could not copy from bitmap: %#lx",
__FUNCTION__, hr);
90 D2D1_MAPPED_RECT mappedRect;
91 hr = mappingCopy->Map(D2D1_MAP_OPTIONS_READ, &mappedRect);
93 qWarning(
"%s: Could not map: %#lx",
__FUNCTION__, hr);
97 return QImage(
static_cast<
const uchar *>(mappedRect.bits),
98 int(size.width),
int(size.height),
int(mappedRect.pitch),
99 QImage::Format_ARGB32_Premultiplied).copy(rect);