aboutsummaryrefslogtreecommitdiff
path: root/src/win/graphics/direct/ImageFactory.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-05-07 20:53:57 +0800
committerGitHub <noreply@github.com>2022-05-07 20:53:57 +0800
commitee5aa17e44cb36b386e89032cab96caf87b5b524 (patch)
treea7cef6c60f55e3870900016e0f1a4efe578efbf0 /src/win/graphics/direct/ImageFactory.cpp
parent5bc684dcc1d121bf6e02d0800174c7977c72d101 (diff)
parentcb850a6d6d13fc5b2c0cdd8773e368e23252c459 (diff)
downloadcru-ee5aa17e44cb36b386e89032cab96caf87b5b524.tar.gz
cru-ee5aa17e44cb36b386e89032cab96caf87b5b524.tar.bz2
cru-ee5aa17e44cb36b386e89032cab96caf87b5b524.zip
Merge pull request #54 from crupest/create-image
Diffstat (limited to 'src/win/graphics/direct/ImageFactory.cpp')
-rw-r--r--src/win/graphics/direct/ImageFactory.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/win/graphics/direct/ImageFactory.cpp b/src/win/graphics/direct/ImageFactory.cpp
index e7794aa5..49fc49e8 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<IImage> WinImageFactory::DecodeFromStream(io::Stream* stream) {
return std::make_unique<Direct2DImage>(graphics_factory_,
std::move(d2d_image));
}
+
+std::unique_ptr<IImage> 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<ID2D1Bitmap> bitmap;
+
+ auto d2d_context = graphics_factory_->GetDefaultD2D1DeviceContext();
+ d2d_context->CreateBitmap(
+ D2D1::SizeU(width, height),
+ D2D1::BitmapProperties(D2D1::PixelFormat(DXGI_FORMAT_R8G8B8A8_UINT,
+ D2D1_ALPHA_MODE_STRAIGHT)),
+ &bitmap);
+
+ Microsoft::WRL::ComPtr<ID2D1Bitmap1> bitmap1;
+ ThrowIfFailed(bitmap.As(&bitmap1), "Failed to convert bitmap to bitmap1.");
+
+ return std::make_unique<Direct2DImage>(graphics_factory_, std::move(bitmap1));
+}
} // namespace cru::platform::graphics::win::direct