问题描述
我正在使用 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 (将#修改为@)