diff --git a/src/samples/DirectDraw/Direct2dDemo/Program.cs b/src/samples/DirectDraw/Direct2dDemo/Program.cs
index fb9a53c..6502e7e 100644
--- a/src/samples/DirectDraw/Direct2dDemo/Program.cs
+++ b/src/samples/DirectDraw/Direct2dDemo/Program.cs
@@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Drawing;
-using System.Numerics;
using Windows;
using Windows.Win32.Graphics.Direct2D;
@@ -18,7 +17,10 @@ private class Direct2dDemo : MainWindow
private SolidColorBrush? _lightSlateGrayBrush;
private SolidColorBrush? _cornflowerBlueBrush;
- public Direct2dDemo() : base(title: "Simple Direct2D Application", features: Features.EnableDirect2d)
+ public Direct2dDemo() : base(
+ title: "Simple Direct2D Application",
+ backgroundColor: Color.White,
+ features: Features.EnableDirect2d)
{
}
@@ -33,9 +35,6 @@ protected override void RenderTargetCreated()
protected override void OnPaint()
{
- RenderTarget.SetTransform(Matrix3x2.Identity);
- RenderTarget.Clear(Color.White);
-
SizeF size = RenderTarget.Size();
for (int x = 0; x < size.Width; x += 10)
diff --git a/src/samples/DirectDraw/DirectWriteDemo/Program.cs b/src/samples/DirectDraw/DirectWriteDemo/Program.cs
index 8bac399..9d96d75 100644
--- a/src/samples/DirectDraw/DirectWriteDemo/Program.cs
+++ b/src/samples/DirectDraw/DirectWriteDemo/Program.cs
@@ -24,7 +24,10 @@ private class DirectWriteDemo : MainWindow
protected SolidColorBrush? _blackBrush;
- public DirectWriteDemo() : base(title: "Simple DirectWrite Application", features: Features.EnableDirect2d)
+ public DirectWriteDemo() : base(
+ title: "Simple DirectWrite Application",
+ backgroundColor: Color.CornflowerBlue,
+ features: Features.EnableDirect2d)
{
_textFormat = new("Gabriola", fontSize: 64)
{
@@ -45,8 +48,7 @@ protected override void RenderTargetCreated()
protected override void OnPaint()
{
- RenderTarget.Clear(Color.CornflowerBlue);
- RenderTarget.DrawTextLayout(default, _textLayout!, _blackBrush!);
+ RenderTarget.DrawTextLayout(origin: default, _textLayout!, _blackBrush!);
}
protected override void OnSize(Size size)
diff --git a/src/samples/DirectDraw/ImagingDemo/Blue Marble 2012 Original.jpg b/src/samples/DirectDraw/ImagingDemo/Blue Marble 2012 Original.jpg
new file mode 100644
index 0000000..7edb2f7
Binary files /dev/null and b/src/samples/DirectDraw/ImagingDemo/Blue Marble 2012 Original.jpg differ
diff --git a/src/samples/DirectDraw/ImagingDemo/ImagingDemo.csproj b/src/samples/DirectDraw/ImagingDemo/ImagingDemo.csproj
new file mode 100644
index 0000000..2712e6b
--- /dev/null
+++ b/src/samples/DirectDraw/ImagingDemo/ImagingDemo.csproj
@@ -0,0 +1,18 @@
+
+
+
+ WinExe
+ true
+
+
+
+
+
+
+
+
+ PreserveNewest
+
+
+
+
diff --git a/src/samples/DirectDraw/ImagingDemo/Program.cs b/src/samples/DirectDraw/ImagingDemo/Program.cs
new file mode 100644
index 0000000..1012f19
--- /dev/null
+++ b/src/samples/DirectDraw/ImagingDemo/Program.cs
@@ -0,0 +1,73 @@
+// Copyright (c) Jeremy W. Kuhne. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using System.Diagnostics.CodeAnalysis;
+using System.Drawing;
+using Windows;
+using Windows.Win32.Graphics.Direct2D;
+using Windows.Win32.Graphics.Imaging;
+using Bitmap = Windows.Win32.Graphics.Direct2D.Bitmap;
+
+namespace ImagingDemo;
+
+internal class Program
+{
+ [STAThread]
+ private static void Main() => Application.Run(new ImagingDemo());
+
+ private unsafe class ImagingDemo : MainWindow
+ {
+ private FormatConverter? _converter;
+ private Bitmap? _bitmap;
+
+
+ public ImagingDemo() : base(
+ title: "Simple Windows Imaging Application",
+ backgroundColor: Color.Black,
+ features: Features.EnableDirect2d)
+ {
+ }
+
+ [MemberNotNull(nameof(_converter))]
+ private void CreateBitmapFromFile(string fileName)
+ {
+ _converter?.Dispose();
+ _bitmap?.Dispose();
+
+ using BitmapDecoder decoder = new(fileName);
+ using BitmapFrameDecode frame = decoder.GetFrame(0);
+ _converter = new(frame);
+ }
+
+ protected override void RenderTargetCreated()
+ {
+ if (_converter is null)
+ {
+ CreateBitmapFromFile("Blue Marble 2012 Original.jpg");
+ }
+
+ _bitmap?.Dispose();
+ _bitmap = RenderTarget.CreateBitmapFromWicBitmap(_converter);
+ base.RenderTargetCreated();
+ }
+
+ protected override void OnPaint()
+ {
+ if (_bitmap is not null)
+ {
+ RenderTarget.DrawBitmap(_bitmap);
+ }
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ _converter?.Dispose();
+ _bitmap?.Dispose();
+ }
+
+ base.Dispose(disposing);
+ }
+ }
+}
diff --git a/src/samples/DirectDraw/ImagingDemo/readme.txt b/src/samples/DirectDraw/ImagingDemo/readme.txt
new file mode 100644
index 0000000..7c07f8f
--- /dev/null
+++ b/src/samples/DirectDraw/ImagingDemo/readme.txt
@@ -0,0 +1,3 @@
+"Blue Marble 2012 Original"" image is in the public domain.
+Credit: NASA/NOAA/GSFC/Suomi NPP/VIIRS/Norman Kuring
+Source: https://flickr.com/photos/nasacommons/31258502484/
\ No newline at end of file
diff --git a/src/thirtytwo/Application.cs b/src/thirtytwo/Application.cs
index 6341795..45592fd 100644
--- a/src/thirtytwo/Application.cs
+++ b/src/thirtytwo/Application.cs
@@ -6,6 +6,7 @@
using Windows.Support;
using Windows.Win32.Graphics.Direct2D;
using Windows.Win32.Graphics.DirectWrite;
+using Windows.Win32.Graphics.Imaging;
namespace Windows;
@@ -15,6 +16,7 @@ public static unsafe class Application
private static Direct2dFactory? s_direct2dFactory;
private static DirectWriteFactory? s_directWriteFactory;
private static DirectWriteGdiInterop? s_directWriteGdiInterop;
+ private static ImagingFactory? s_imagingFactory;
internal static ActivationScope ThemingScope => new(GetStylesContext());
@@ -229,4 +231,5 @@ public static string GetUserDefaultLocaleName()
public static Direct2dFactory Direct2dFactory => s_direct2dFactory ??= new();
public static DirectWriteFactory DirectWriteFactory => s_directWriteFactory ??= new();
public static DirectWriteGdiInterop DirectWriteGdiInterop => s_directWriteGdiInterop ??= new();
+ public static ImagingFactory ImagingFactory => s_imagingFactory ??= new();
}
\ No newline at end of file
diff --git a/src/thirtytwo/NativeMethods.txt b/src/thirtytwo/NativeMethods.txt
index e3fc20e..3482d86 100644
--- a/src/thirtytwo/NativeMethods.txt
+++ b/src/thirtytwo/NativeMethods.txt
@@ -362,4 +362,7 @@ VIRTUAL_KEY
WIN32_ERROR
WINDOWPOS
WM_*
-XFORMCOORDS
\ No newline at end of file
+XFORMCOORDS
+IWICImagingFactory2
+CLSID_WICImagingFactory2
+GUID_WICPixelFormat32bppPBGRA
\ No newline at end of file
diff --git a/src/thirtytwo/Win32/Graphics/Direct2D/Bitmap.cs b/src/thirtytwo/Win32/Graphics/Direct2D/Bitmap.cs
new file mode 100644
index 0000000..ca652cd
--- /dev/null
+++ b/src/thirtytwo/Win32/Graphics/Direct2D/Bitmap.cs
@@ -0,0 +1,17 @@
+// Copyright (c) Jeremy W. Kuhne. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using Windows.Support;
+
+namespace Windows.Win32.Graphics.Direct2D;
+
+public unsafe class Bitmap : Image, IPointer
+{
+ public unsafe new ID2D1Bitmap* Pointer => (ID2D1Bitmap*)base.Pointer;
+
+ public Bitmap(ID2D1Bitmap* bitmap) : base((ID2D1Image*)bitmap)
+ {
+ }
+
+ public static implicit operator ID2D1Bitmap*(Bitmap bitmap) => bitmap.Pointer;
+}
\ No newline at end of file
diff --git a/src/thirtytwo/Win32/Graphics/Direct2D/BitmapInterpolationMode.cs b/src/thirtytwo/Win32/Graphics/Direct2D/BitmapInterpolationMode.cs
new file mode 100644
index 0000000..cde45a6
--- /dev/null
+++ b/src/thirtytwo/Win32/Graphics/Direct2D/BitmapInterpolationMode.cs
@@ -0,0 +1,13 @@
+// Copyright (c) Jeremy W. Kuhne. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+namespace Windows.Win32.Graphics.Direct2D;
+
+public enum BitmapInterpolationMode
+{
+ ///
+ NearestNeighbor = D2D1_BITMAP_INTERPOLATION_MODE.D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
+
+ ///
+ Linear = D2D1_BITMAP_INTERPOLATION_MODE.D2D1_BITMAP_INTERPOLATION_MODE_LINEAR
+}
\ No newline at end of file
diff --git a/src/thirtytwo/Win32/Graphics/Direct2D/HwndRenderTarget.cs b/src/thirtytwo/Win32/Graphics/Direct2D/HwndRenderTarget.cs
index 2d1b56f..bf042ad 100644
--- a/src/thirtytwo/Win32/Graphics/Direct2D/HwndRenderTarget.cs
+++ b/src/thirtytwo/Win32/Graphics/Direct2D/HwndRenderTarget.cs
@@ -7,6 +7,14 @@
namespace Windows.Win32.Graphics.Direct2D;
+///
+/// render target.
+///
+///
+///
+/// Supported Formats for ID2D1HwndRenderTarget
+///
+///
public unsafe class HwndRenderTarget : RenderTarget, IPointer
{
public new ID2D1HwndRenderTarget* Pointer => (ID2D1HwndRenderTarget*)base.Pointer;
@@ -34,6 +42,8 @@ public static HwndRenderTarget CreateForWindow(
where TFactory : IPointer
where TWindow : IHandle
{
+ // DXGI_FORMAT_B8G8R8A8_UNORM is the recommended pixel format for HwndRenderTarget for performance reasons.
+ // DXGI_FORMAT_UNKNOWN and DXGI_FORMAT_UNKNOWN give DXGI_FORMAT_B8G8R8A8_UNORM and D2D1_ALPHA_MODE_IGNORE.
D2D1_RENDER_TARGET_PROPERTIES properties = default;
D2D1_HWND_RENDER_TARGET_PROPERTIES hwndProperties = new()
{
diff --git a/src/thirtytwo/Win32/Graphics/Direct2D/Image.cs b/src/thirtytwo/Win32/Graphics/Direct2D/Image.cs
new file mode 100644
index 0000000..2475a03
--- /dev/null
+++ b/src/thirtytwo/Win32/Graphics/Direct2D/Image.cs
@@ -0,0 +1,17 @@
+// Copyright (c) Jeremy W. Kuhne. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using Windows.Support;
+
+namespace Windows.Win32.Graphics.Direct2D;
+
+public unsafe class Image : Resource, IPointer
+{
+ public unsafe new ID2D1Image* Pointer => (ID2D1Image*)base.Pointer;
+
+ public Image(ID2D1Image* image) : base((ID2D1Resource*)image)
+ {
+ }
+
+ public static implicit operator ID2D1Image*(Image image) => image.Pointer;
+}
\ No newline at end of file
diff --git a/src/thirtytwo/Win32/Graphics/Direct2D/InterpolationMode.cs b/src/thirtytwo/Win32/Graphics/Direct2D/InterpolationMode.cs
new file mode 100644
index 0000000..8eab6a9
--- /dev/null
+++ b/src/thirtytwo/Win32/Graphics/Direct2D/InterpolationMode.cs
@@ -0,0 +1,25 @@
+// Copyright (c) Jeremy W. Kuhne. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+namespace Windows.Win32.Graphics.Direct2D;
+
+public enum InterpolationMode
+{
+ ///
+ NearestNeighbor = D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
+
+ ///
+ Linear = D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_LINEAR,
+
+ ///
+ Cubic = D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_CUBIC,
+
+ ///
+ MultiSampleLinear = D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_MULTI_SAMPLE_LINEAR,
+
+ ///
+ Anisotropic = D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_ANISOTROPIC,
+
+ ///
+ HighQualityCubic = D2D1_INTERPOLATION_MODE.D2D1_INTERPOLATION_MODE_HIGH_QUALITY_CUBIC
+}
\ No newline at end of file
diff --git a/src/thirtytwo/Win32/Graphics/Direct2D/RenderTargetExtensions.cs b/src/thirtytwo/Win32/Graphics/Direct2D/RenderTargetExtensions.cs
index 31162e0..efc2aef 100644
--- a/src/thirtytwo/Win32/Graphics/Direct2D/RenderTargetExtensions.cs
+++ b/src/thirtytwo/Win32/Graphics/Direct2D/RenderTargetExtensions.cs
@@ -6,6 +6,7 @@
using Windows.Support;
using Windows.Win32.Graphics.Direct2D.Common;
using Windows.Win32.Graphics.DirectWrite;
+using Windows.Win32.Graphics.Imaging;
namespace Windows.Win32.Graphics.Direct2D;
@@ -115,4 +116,54 @@ public static void DrawTextLayout(
GC.KeepAlive(textLayout);
GC.KeepAlive(defaultFillBrush);
}
+
+ ///
+ public static Bitmap CreateBitmapFromWicBitmap(
+ this TRenderTarget target,
+ TBitmapSource wicBitmap)
+ where TRenderTarget : IPointer
+ where TBitmapSource : IPointer
+ {
+ ID2D1Bitmap* d2dBitmap;
+ target.Pointer->CreateBitmapFromWicBitmap(
+ wicBitmap.Pointer,
+ bitmapProperties: (D2D1_BITMAP_PROPERTIES*)null,
+ &d2dBitmap).ThrowOnFailure();
+
+ Bitmap bitmap = new(d2dBitmap);
+ GC.KeepAlive(target);
+ GC.KeepAlive(wicBitmap);
+ return bitmap;
+ }
+
+ public static void DrawBitmap(
+ this TRenderTarget target,
+ TBitmap bitmap,
+ RectangleF destinationRectangle = default,
+ float opacity = 1.0f,
+ BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.Linear)
+ where TRenderTarget : IPointer
+ where TBitmap : IPointer
+ {
+ D2D_RECT_F destination = (D2D_RECT_F)destinationRectangle;
+ if (destinationRectangle.IsEmpty)
+ {
+ D2D_SIZE_F size = target.Pointer->GetSizeHack();
+ destination = new D2D_RECT_F { left = 0, top = 0, right = size.width, bottom = size.height };
+ }
+ else
+ {
+ destination = (D2D_RECT_F)destinationRectangle;
+ }
+
+ target.Pointer->DrawBitmap(
+ bitmap.Pointer,
+ &destination,
+ opacity,
+ (D2D1_BITMAP_INTERPOLATION_MODE)interpolationMode,
+ null);
+
+ GC.KeepAlive(target);
+ GC.KeepAlive(bitmap);
+ }
}
\ No newline at end of file
diff --git a/src/thirtytwo/Win32/Graphics/DirectDrawBase.cs b/src/thirtytwo/Win32/Graphics/DirectDrawBase.cs
index a63361b..13f78a4 100644
--- a/src/thirtytwo/Win32/Graphics/DirectDrawBase.cs
+++ b/src/thirtytwo/Win32/Graphics/DirectDrawBase.cs
@@ -6,6 +6,17 @@
namespace Windows.Win32.Graphics;
+///
+/// Base class for DirectDraw objects.
+///
+///
+///
+///
+/// Direct3D, DirectWrite, and Direct2D use a lightweight version of the COM specification to manage object lifetime
+/// through interfaces derived from IUnknown. There's no need to initialize the COM run time and worry about apartments
+/// or proxies. It's just a convention to simplify resource management and allow APIs and applications to expose and
+/// consume objects in a well-defined way.
+///
public unsafe abstract class DirectDrawBase : DisposableBase.Finalizable, IPointer where T : unmanaged
{
private nint _pointer;
diff --git a/src/thirtytwo/Win32/Graphics/Imaging/BitmapDecoder.cs b/src/thirtytwo/Win32/Graphics/Imaging/BitmapDecoder.cs
new file mode 100644
index 0000000..081748f
--- /dev/null
+++ b/src/thirtytwo/Win32/Graphics/Imaging/BitmapDecoder.cs
@@ -0,0 +1,41 @@
+// Copyright (c) Jeremy W. Kuhne. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+namespace Windows.Win32.Graphics.Imaging;
+
+public unsafe class BitmapDecoder : DirectDrawBase
+{
+ public BitmapDecoder(IWICBitmapDecoder* pointer) : base(pointer) { }
+
+ public BitmapDecoder(string filename, WICDecodeOptions metadataOptions = WICDecodeOptions.WICDecodeMetadataCacheOnDemand)
+ : base(CreateDecoderFromFilename(Application.ImagingFactory, filename, metadataOptions))
+ {
+ }
+
+ public static IWICBitmapDecoder* CreateDecoderFromFilename(
+ ImagingFactory factory,
+ string filename,
+ WICDecodeOptions metadataOptions = WICDecodeOptions.WICDecodeMetadataCacheOnDemand)
+ {
+ IWICBitmapDecoder* decoder;
+ factory.Pointer->CreateDecoderFromFilename(
+ filename,
+ null,
+ GENERIC_ACCESS_RIGHTS.GENERIC_READ,
+ metadataOptions,
+ &decoder).ThrowOnFailure();
+
+ GC.KeepAlive(factory);
+ return decoder;
+ }
+
+ public BitmapFrameDecode GetFrame(uint index)
+ {
+ IWICBitmapFrameDecode* frame;
+ Pointer->GetFrame(index, &frame).ThrowOnFailure();
+ GC.KeepAlive(this);
+ return new BitmapFrameDecode(frame);
+ }
+
+ public static implicit operator IWICBitmapDecoder*(BitmapDecoder d) => d.Pointer;
+}
\ No newline at end of file
diff --git a/src/thirtytwo/Win32/Graphics/Imaging/BitmapFrameDecode.cs b/src/thirtytwo/Win32/Graphics/Imaging/BitmapFrameDecode.cs
new file mode 100644
index 0000000..9dfae5c
--- /dev/null
+++ b/src/thirtytwo/Win32/Graphics/Imaging/BitmapFrameDecode.cs
@@ -0,0 +1,15 @@
+// Copyright (c) Jeremy W. Kuhne. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using Windows.Support;
+
+namespace Windows.Win32.Graphics.Imaging;
+
+public unsafe class BitmapFrameDecode : BitmapSource, IPointer
+{
+ public new IWICBitmapFrameDecode* Pointer => (IWICBitmapFrameDecode*)base.Pointer;
+
+ public BitmapFrameDecode(IWICBitmapFrameDecode* pointer) : base((IWICBitmapSource*)pointer) { }
+
+ public static implicit operator IWICBitmapFrameDecode*(BitmapFrameDecode d) => d.Pointer;
+}
\ No newline at end of file
diff --git a/src/thirtytwo/Win32/Graphics/Imaging/BitmapSource.cs b/src/thirtytwo/Win32/Graphics/Imaging/BitmapSource.cs
new file mode 100644
index 0000000..3464009
--- /dev/null
+++ b/src/thirtytwo/Win32/Graphics/Imaging/BitmapSource.cs
@@ -0,0 +1,11 @@
+// Copyright (c) Jeremy W. Kuhne. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+namespace Windows.Win32.Graphics.Imaging;
+
+public unsafe class BitmapSource : DirectDrawBase
+{
+ public BitmapSource(IWICBitmapSource* pointer) : base(pointer) { }
+
+ public static implicit operator IWICBitmapSource*(BitmapSource d) => d.Pointer;
+}
\ No newline at end of file
diff --git a/src/thirtytwo/Win32/Graphics/Imaging/FormatConverter.cs b/src/thirtytwo/Win32/Graphics/Imaging/FormatConverter.cs
new file mode 100644
index 0000000..fd43604
--- /dev/null
+++ b/src/thirtytwo/Win32/Graphics/Imaging/FormatConverter.cs
@@ -0,0 +1,50 @@
+// Copyright (c) Jeremy W. Kuhne. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using Windows.Support;
+
+namespace Windows.Win32.Graphics.Imaging;
+
+public unsafe class FormatConverter : BitmapSource, IPointer
+{
+ public new IWICFormatConverter* Pointer => (IWICFormatConverter*)base.Pointer;
+
+ public FormatConverter(IWICFormatConverter* pointer) : base((IWICBitmapSource*)pointer) { }
+ public FormatConverter() : this(Create()) { }
+ public FormatConverter(BitmapSource source) : this(Create()) => Initialize(source);
+
+
+ private static IWICFormatConverter* Create()
+ {
+ IWICFormatConverter* converter;
+ Application.ImagingFactory.Pointer->CreateFormatConverter(&converter).ThrowOnFailure();
+ return converter;
+ }
+
+ public void Initialize(
+ T source,
+ Guid destinationFormat = default,
+ WICBitmapDitherType dither = WICBitmapDitherType.WICBitmapDitherTypeNone,
+ IWICPalette* palette = null,
+ float alphaThresholdPercent = 0.0f,
+ WICBitmapPaletteType paletteTranslate = WICBitmapPaletteType.WICBitmapPaletteTypeCustom)
+ where T : IPointer
+ {
+ if (destinationFormat == Guid.Empty)
+ {
+ destinationFormat = Interop.GUID_WICPixelFormat32bppPBGRA;
+ }
+
+ Pointer->Initialize(
+ source.Pointer,
+ &destinationFormat,
+ dither,
+ palette,
+ alphaThresholdPercent,
+ paletteTranslate).ThrowOnFailure();
+
+ GC.KeepAlive(source);
+ }
+
+ public static implicit operator IWICFormatConverter*(FormatConverter d) => d.Pointer;
+}
\ No newline at end of file
diff --git a/src/thirtytwo/Win32/Graphics/Imaging/ImagingFactory.cs b/src/thirtytwo/Win32/Graphics/Imaging/ImagingFactory.cs
new file mode 100644
index 0000000..41e5207
--- /dev/null
+++ b/src/thirtytwo/Win32/Graphics/Imaging/ImagingFactory.cs
@@ -0,0 +1,27 @@
+// Copyright (c) Jeremy W. Kuhne. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using Windows.Win32.Graphics.Imaging.D2D;
+using Windows.Win32.System.Com;
+
+namespace Windows.Win32.Graphics.Imaging;
+
+public unsafe class ImagingFactory : DirectDrawBase
+{
+ public ImagingFactory() : base(Create()) { }
+
+ public ImagingFactory(IWICImagingFactory2* pointer) : base(pointer) { }
+
+ private static IWICImagingFactory2* Create()
+ {
+ Interop.CoCreateInstance(
+ Interop.CLSID_WICImagingFactory2,
+ null,
+ CLSCTX.CLSCTX_INPROC_SERVER,
+ out IWICImagingFactory2* factory).ThrowOnFailure();
+
+ return factory;
+ }
+
+ public static implicit operator IWICImagingFactory2*(ImagingFactory d) => d.Pointer;
+}
\ No newline at end of file
diff --git a/src/thirtytwo/Window.cs b/src/thirtytwo/Window.cs
index d9f6274..f50c1be 100644
--- a/src/thirtytwo/Window.cs
+++ b/src/thirtytwo/Window.cs
@@ -3,6 +3,7 @@
using System.Collections.Concurrent;
using System.Drawing;
+using System.Numerics;
using Windows.Components;
using Windows.Support;
using Windows.Win32.Graphics.Direct2D;
@@ -247,6 +248,7 @@ private LRESULT WindowProcedureInternal(HWND window, uint message, WPARAM wParam
if (IsDirect2dEnabled())
{
_renderTarget.BeginDraw();
+ _renderTarget.SetTransform(Matrix3x2.Identity);
_renderTarget.Clear(_backgroundColor);
}
diff --git a/thirtytwo.sln b/thirtytwo.sln
index 62b8a8e..84ecfef 100644
--- a/thirtytwo.sln
+++ b/thirtytwo.sln
@@ -61,6 +61,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Direct2dDemo", "src\samples
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DirectWriteDemo", "src\samples\DirectDraw\DirectWriteDemo\DirectWriteDemo.csproj", "{24BAE093-7546-4ED1-AF5C-2A62AD244C63}"
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImagingDemo", "src\samples\DirectDraw\ImagingDemo\ImagingDemo.csproj", "{4CF43863-B039-4DB8-BB1E-0AB825A4A09E}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -151,6 +153,10 @@ Global
{24BAE093-7546-4ED1-AF5C-2A62AD244C63}.Debug|x64.Build.0 = Debug|x64
{24BAE093-7546-4ED1-AF5C-2A62AD244C63}.Release|x64.ActiveCfg = Release|x64
{24BAE093-7546-4ED1-AF5C-2A62AD244C63}.Release|x64.Build.0 = Release|x64
+ {4CF43863-B039-4DB8-BB1E-0AB825A4A09E}.Debug|x64.ActiveCfg = Debug|x64
+ {4CF43863-B039-4DB8-BB1E-0AB825A4A09E}.Debug|x64.Build.0 = Debug|x64
+ {4CF43863-B039-4DB8-BB1E-0AB825A4A09E}.Release|x64.ActiveCfg = Release|x64
+ {4CF43863-B039-4DB8-BB1E-0AB825A4A09E}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -177,6 +183,7 @@ Global
{7107A105-51E2-46EB-859D-E2DD2FD51839} = {C059056C-D771-4CF5-A93F-AA7140FF7827}
{1EC566E8-C337-42FF-9BA4-DB66BFAE5B8A} = {7107A105-51E2-46EB-859D-E2DD2FD51839}
{24BAE093-7546-4ED1-AF5C-2A62AD244C63} = {7107A105-51E2-46EB-859D-E2DD2FD51839}
+ {4CF43863-B039-4DB8-BB1E-0AB825A4A09E} = {7107A105-51E2-46EB-859D-E2DD2FD51839}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3761BFC9-DBEF-4186-BB8B-BC0D84ED9AE5}