protected override void Dispose(DisposeTypes type) { if (disposed) { return; } if (type == DisposeTypes.Explicit) { //Called by User //Release your own managed resources here. //You should release all of your own disposable objects here. mCachedBuffer?.Dispose(); } base.Dispose(type); }
public static PixelBuffer LoadImageFromBuffer(System.IO.Stream stream, Size2D size) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } if (size == null) { throw new ArgumentNullException(nameof(size)); } long streamLength = stream.Length - stream.Position; if (streamLength <= 0) { throw new InvalidOperationException("stream lenght is <= 0"); } // Read data from stream byte[] streamData = new byte[streamLength]; stream.Read(streamData, 0, (int)streamLength); // Allocate buffer that internal DALi engine can read VectorUnsignedChar buffer = new VectorUnsignedChar(); buffer.Resize((uint)streamLength); var bufferBegin = buffer.Begin(); global::System.Runtime.InteropServices.HandleRef bufferRef = SWIGTYPE_p_unsigned_char.getCPtr(bufferBegin); // Copy data from stream to buffer System.Runtime.InteropServices.Marshal.Copy(streamData, 0, bufferRef.Handle, (int)streamLength); var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height); PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.LoadImageFromBuffer(VectorUnsignedChar.getCPtr(buffer), Uint16Pair.getCPtr(uSize)), true); uSize.Dispose(); buffer.Dispose(); if (NDalicPINVOKE.SWIGPendingException.Pending) { throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }