Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 50 additions & 16 deletions FlyleafLib/MediaFramework/MediaRenderer/Renderer.Snapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,10 @@ Snapshot GetSnapshot(uint width, uint height)
return snapshot = new(device, vd, ve, width, height);
}

public Bitmap TakeSnapshot(uint width = 0, uint height = 0)
ID3D11Texture2D GetTexture(Snapshot snapshot)
{
try
{
if (width == 0 && height == 0)
{
width = VisibleWidth;
height = VisibleHeight;
}
else if (width != 0 && height == 0)
height = (uint)(width / curRatio);
else if (height != 0 && width == 0)
width = (uint)(height * curRatio);

var snapshot = GetSnapshot(width, height);

lock (lockRenderLoops)
{
var rFrame = Frames.RendererFrame;
Expand All @@ -70,12 +58,58 @@ public Bitmap TakeSnapshot(uint width = 0, uint height = 0)
context.RSSetViewport(Viewport);
}
}

context.CopyResource(snapshot.txtStage, snapshot.txt);

return GetBitmap(snapshot.txtStage);
return snapshot.txtStage;
}
catch { return null; }
}

public Bitmap TakeSnapshot(uint width = 0, uint height = 0)
{
try
{
if (width == 0 && height == 0)
{
width = VisibleWidth;
height = VisibleHeight;
}
else if (width != 0 && height == 0)
height = (uint)(width / curRatio);
else if (height != 0 && width == 0)
width = (uint)(height * curRatio);

var snapshot = GetSnapshot(width, height);
var texture = GetTexture(snapshot);
if (texture is null)
return null;
return GetBitmap(texture);
}
catch { return null; }
}

public BitmapSource TakeSnapshotBitmapSource(uint width = 0, uint height = 0)
{
try
{
if (width == 0 && height == 0)
{
width = VisibleWidth;
height = VisibleHeight;
}
else if (width != 0 && height == 0)
height = (uint)(width / curRatio);
else if (height != 0 && width == 0)
width = (uint)(height * curRatio);

var snapshot = GetSnapshot(width, height);
var texture = GetTexture(snapshot);
if (texture is null)
return null;
return GetBitmapSource(texture);
}
catch { return null; }
catch { return null; }
}

#region Bitmap Helpers
Expand Down
10 changes: 10 additions & 0 deletions FlyleafLib/MediaPlayer/Player.Extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,16 @@ public void TakeSnapshotToFile(string filename = null, uint width = 0, uint heig
/// <returns></returns>
public System.Drawing.Bitmap TakeSnapshotToBitmap(uint width = 0, uint height = 0) => Renderer?.TakeSnapshot(width, height);

/// <summary>
/// <para>Returns a bitmap of the current or specified video frame</para>
/// <para>If width/height not specified will use the original size. If one of them will be set, the other one will be set based on original ratio</para>
/// <para>If frame not specified will use the current/last frame</para>
/// </summary>
/// <param name="width">Specify the width (0: will keep the ratio based on height)</param>
/// <param name="height">Specify the height (0: will keep the ratio based on width)</param>
/// <returns></returns>
public System.Windows.Media.Imaging.BitmapSource TakeSnapshotToBitmapSource(uint width = 0, uint height = 0) => Renderer?.TakeSnapshotBitmapSource(width, height);

public void ResetAll()
{
ReversePlayback = false;
Expand Down