mirror of
https://github.com/ZuneDev/MicrosoftIris.git
synced 2026-07-27 13:13:29 -07:00
Add ability to load dynamics resources and consequently images from external C# code
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user