From a465e2c410c1ae5098d2e073442219bb07a31b9d Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 7 May 2022 18:39:51 +0800 Subject: ... --- src/win/graphics/direct/ImageFactory.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/win/graphics/direct/ImageFactory.cpp') diff --git a/src/win/graphics/direct/ImageFactory.cpp b/src/win/graphics/direct/ImageFactory.cpp index e7794aa5..76694e30 100644 --- a/src/win/graphics/direct/ImageFactory.cpp +++ b/src/win/graphics/direct/ImageFactory.cpp @@ -1,4 +1,5 @@ #include "cru/win/graphics/direct/ImageFactory.h" +#include "cru/common/platform/win/Exception.h" #include "cru/common/platform/win/StreamConvert.h" #include "cru/win/graphics/direct/Exception.h" #include "cru/win/graphics/direct/Factory.h" @@ -42,4 +43,23 @@ std::unique_ptr WinImageFactory::DecodeFromStream(io::Stream* stream) { return std::make_unique(graphics_factory_, std::move(d2d_image)); } + +std::unique_ptr WinImageFactory::CreateBitmap(int width, int height) { + if (width <= 0) throw Exception(u"Bitmap width must be greater than 0."); + if (height <= 0) throw Exception(u"Bitmap height must be greater than 0."); + + Microsoft::WRL::ComPtr bitmap; + + auto d2d_context = graphics_factory_->GetDefaultD2D1DeviceContext(); + d2d_context->CreateBitmap( + D2D1::SizeU(width, height), + D2D1::BitmapProperties(D2D1::PixelFormat(DXGI_FORMAT_R8G8B8A8_TYPELESS, + D2D1_ALPHA_MODE_STRAIGHT)), + &bitmap); + + Microsoft::WRL::ComPtr bitmap1; + ThrowIfFailed(bitmap.As(&bitmap1), "Failed to convert bitmap to bitmap1."); + + return std::make_unique(graphics_factory_, std::move(bitmap1)); +} } // namespace cru::platform::graphics::win::direct -- cgit v1.2.3 From 9ef6b6886725178e70aedb64d52c742da1f45328 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 7 May 2022 18:46:08 +0800 Subject: ... --- src/win/graphics/direct/ImageFactory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/win/graphics/direct/ImageFactory.cpp') diff --git a/src/win/graphics/direct/ImageFactory.cpp b/src/win/graphics/direct/ImageFactory.cpp index 76694e30..49fc49e8 100644 --- a/src/win/graphics/direct/ImageFactory.cpp +++ b/src/win/graphics/direct/ImageFactory.cpp @@ -53,7 +53,7 @@ std::unique_ptr WinImageFactory::CreateBitmap(int width, int height) { auto d2d_context = graphics_factory_->GetDefaultD2D1DeviceContext(); d2d_context->CreateBitmap( D2D1::SizeU(width, height), - D2D1::BitmapProperties(D2D1::PixelFormat(DXGI_FORMAT_R8G8B8A8_TYPELESS, + D2D1::BitmapProperties(D2D1::PixelFormat(DXGI_FORMAT_R8G8B8A8_UINT, D2D1_ALPHA_MODE_STRAIGHT)), &bitmap); -- cgit v1.2.3