home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 2
General
Concept: Switch MP2 to D3D11/D2D rendering
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="morpheus_xx" data-source="post: 1121342" data-attributes="member: 48495"><p>Let's combine few parts for an example:</p><p>[CODE=CSHARP]var bitmapWidth = 100;</p><p>var bitmapHeight = 100;</p><p>var targetRect = new RectangleF(0f, 0f, bitmapWidth, bitmapHeight);</p><p>Bitmap1 captureFrame = new Bitmap1(...); // target bitmap. Format must match backbuffer one, size you specify</p><p>using (new TemporaryRenderTarget2D(captureFrame)) // tells the 2D context to draw on captureFrame</p><p>{</p><p> BitmapBrushProperties1 props = new BitmapBrushProperties1</p><p> {</p><p> ExtendModeX = ExtendMode.Clamp,</p><p> ExtendModeY = ExtendMode.Clamp,</p><p> InterpolationMode = GraphicsDevice11.Instance.ImageInterpolationMode</p><p> };</p><p></p><p> var backbuffer = SkinContext.Device11.RenderTarget2D;</p><p> // Note: resource creation is expensive, store all device-resources in fields and make sure to dispose them when no longer needed!</p><p> using (var bmpBrush = new BitmapBrush1(GraphicsDevice11.Instance.Context2D1, backbuffer , props))</p><p> using (var rectGeom = new RectangleGeometry(GraphicsDevice11.Instance.Context2D1.Factory, targetRect))</p><p> { </p><p> // Need to adjust the BitmapBrush to match input/output dimension and position. Should also be done only once</p><p> Matrix3x2 brushTransform = Matrix3x2.Identity; </p><p> brushTransform *= Matrix3x2.Scaling(targetRect.Width / backbuffer.PixelSize.Width, targetRect.Height / backbuffer.PixelSize.Height);</p><p> brushTransform *= Matrix3x2.Translation(targetRect.X, targetRect.Y);</p><p> bmpBrush.Transform = brushTransform;</p><p> </p><p> // Fills the rectangle with the Bitmap Brush</p><p> GraphicsDevice11.Instance.Context2D1.FillGeometry(rectGeom, bmpBrush);</p><p> }</p><p>}[/CODE]</p><p></p><p>Source: <a href="https://github.com/MediaPortal/MediaPortal-2/blob/171a9df98446c36194ff97ede49f7a7f8cba3692/MediaPortal/Source/UI/SkinEngine/Rendering/ImageContext2D.cs#L188-L203" target="_blank">https://github.com/MediaPortal/MediaPortal-2/blob/171a9df98446c36194ff97ede49f7a7f8cba3692/MediaPortal/Source/UI/SkinEngine/Rendering/ImageContext2D.cs#L188-L203</a></p><p></p><p>Note: there are multiple ways to do this and I have not "benchmarked" them to know which is the most efficient one...</p><p></p><p>Edit: corrected "_bitmap" to "backbuffer"</p></blockquote><p></p>
[QUOTE="morpheus_xx, post: 1121342, member: 48495"] Let's combine few parts for an example: [CODE=CSHARP]var bitmapWidth = 100; var bitmapHeight = 100; var targetRect = new RectangleF(0f, 0f, bitmapWidth, bitmapHeight); Bitmap1 captureFrame = new Bitmap1(...); // target bitmap. Format must match backbuffer one, size you specify using (new TemporaryRenderTarget2D(captureFrame)) // tells the 2D context to draw on captureFrame { BitmapBrushProperties1 props = new BitmapBrushProperties1 { ExtendModeX = ExtendMode.Clamp, ExtendModeY = ExtendMode.Clamp, InterpolationMode = GraphicsDevice11.Instance.ImageInterpolationMode }; var backbuffer = SkinContext.Device11.RenderTarget2D; // Note: resource creation is expensive, store all device-resources in fields and make sure to dispose them when no longer needed! using (var bmpBrush = new BitmapBrush1(GraphicsDevice11.Instance.Context2D1, backbuffer , props)) using (var rectGeom = new RectangleGeometry(GraphicsDevice11.Instance.Context2D1.Factory, targetRect)) { // Need to adjust the BitmapBrush to match input/output dimension and position. Should also be done only once Matrix3x2 brushTransform = Matrix3x2.Identity; brushTransform *= Matrix3x2.Scaling(targetRect.Width / backbuffer.PixelSize.Width, targetRect.Height / backbuffer.PixelSize.Height); brushTransform *= Matrix3x2.Translation(targetRect.X, targetRect.Y); bmpBrush.Transform = brushTransform; // Fills the rectangle with the Bitmap Brush GraphicsDevice11.Instance.Context2D1.FillGeometry(rectGeom, bmpBrush); } }[/CODE] Source: [url]https://github.com/MediaPortal/MediaPortal-2/blob/171a9df98446c36194ff97ede49f7a7f8cba3692/MediaPortal/Source/UI/SkinEngine/Rendering/ImageContext2D.cs#L188-L203[/url] Note: there are multiple ways to do this and I have not "benchmarked" them to know which is the most efficient one... Edit: corrected "_bitmap" to "backbuffer" [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 2
General
Concept: Switch MP2 to D3D11/D2D rendering
Contact us
RSS
Top
Bottom