如何解决处理旋转屏幕的屏幕捕获脏矩形
我正在使用 SharpDX
捕获屏幕,处理更改并复制到暂存纹理以供稍后保存。
当源屏幕旋转(纵向)时,源纹理不旋转(Documentation says that also)。如何快速旋转纹理并放入我的暂存纹理?
这是我的代码(暂时忽略移动矩形部分,稍后我必须应用相同的内容):
using (var screenTexture = resource.QueryInterface<Texture2D>())
{
#region Moved rectangles (ignore it for now)
var movedRectangles = new OutputDuplicateMoveRectangle[info.TotalMetadataBufferSize];
DuplicatedOutput.GetFrameMoveRects(movedRectangles.Length,movedRectangles,out var movedRegionsLength);
for (var movedIndex = 0; movedIndex < movedRegionsLength / Marshal.SizeOf(typeof(OutputDuplicateMoveRectangle)); movedIndex++)
{
//Crop the destination rectangle to the screen area rectangle.
var left = Math.Max(movedRectangles[movedIndex].DestinationRect.Left,Left);
var right = Math.Min(movedRectangles[movedIndex].DestinationRect.Right,Left + Width);
var top = Math.Max(movedRectangles[movedIndex].DestinationRect.Top,Top);
var bottom = Math.Min(movedRectangles[movedIndex].DestinationRect.Bottom,Top + Height);
//Copies from the screen texture only the area which the user wants to capture.
if (right > left && bottom > top)
{
//Limit the source rectangle to the available size within the destination rectangle.
var sourceWidth = movedRectangles[movedIndex].SourcePoint.X + (right - left);
var sourceHeight = movedRectangles[movedIndex].SourcePoint.Y + (bottom - top);
Device.ImmediateContext.CopySubresourceRegion(screenTexture,new ResourceRegion(movedRectangles[movedIndex].SourcePoint.X,movedRectangles[movedIndex].SourcePoint.Y,sourceWidth,sourceHeight,1),BackingTexture,left - Left,top - Top);
}
}
#endregion
#region Dirty rectangles
var dirtyRectangles = new RawRectangle[info.TotalMetadataBufferSize];
DuplicatedOutput.GetFrameDirtyRects(dirtyRectangles.Length,dirtyRectangles,out var dirtyRegionsLength);
for (var dirtyIndex = 0; dirtyIndex < dirtyRegionsLength / Marshal.SizeOf(typeof(RawRectangle)); dirtyIndex++)
{
//OffsetTop and OffsetLeft are the bounds of the screen
//(where the screen is located within the virtual space).
//Top and Left is the capture position.
//Crop screen positions and size to frame sizes.
var left = Math.Max(dirtyRectangles[dirtyIndex].Left,Left - OffsetLeft);
var right = Math.Min(dirtyRectangles[dirtyIndex].Right,Left + Width - OffsetLeft);
var top = Math.Max(dirtyRectangles[dirtyIndex].Top,Top - OffsetTop);
var bottom = Math.Min(dirtyRectangles[dirtyIndex].Bottom,Top + Height - OffsetTop);
//Copies from the screen texture only the area which the user wants to capture.
if (right > left && bottom > top)
Device.ImmediateContext.CopySubresourceRegion(screenTexture,new ResourceRegion(left,top,right,bottom,left - (Left - OffsetLeft),top - (Top - OffsetTop));
}
#endregion
}
据我所知,dirtyRectangles
数组和 screenTexture
给出的边界是旋转的。
获得正确位置后,我必须先旋转纹理,然后再尝试复制到我的 BackingTexture
。
我的 BackingTexture
是这样创建的:
BackingTexture = new Texture2D(Device,new Texture2DDescription
{
ArraySize = 1,BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,CpuAccessFlags = CpuAccessFlags.None,Format = Format.B8G8R8A8_UNorm,Width = Width,Height = Height,OptionFlags = ResourceOptionFlags.None,MipLevels = 1,SampleDescription = new SampleDescription(1,0),Usage = ResourceUsage.Default
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。