Add ability to load dynamics resources and consequently images from external C# code

This commit is contained in:
Yoshi Askharoun
2023-05-21 18:45:58 -05:00
parent 22b4b39ebc
commit 2a7bc680c4
3 changed files with 60 additions and 11 deletions
+34
View File
@@ -0,0 +1,34 @@
using Microsoft.Iris.Data;
using System.Runtime.InteropServices;
namespace Microsoft.Iris.OS;
public class BytesResource : Resource
{
private byte[] _bytes;
private string _identifier;
private GCHandle _handle;
public BytesResource(string uri, byte[] bytes, string identifier, bool forceSynchronous)
: base(uri, forceSynchronous)
{
_bytes = bytes;
_identifier = identifier;
}
public override string Identifier => _identifier;
protected override void StartAcquisition(bool forceSynchronous)
{
_handle = GCHandle.Alloc(_bytes, GCHandleType.Pinned);
NotifyAcquisitionComplete(_handle.AddrOfPinnedObject(), (uint)_bytes.Length, true, null);
}
protected override void CancelAcquisition()
{
if (!_handle.IsAllocated)
return;
_handle.Free();
}
}