internal EncodedImageBuffer(VectorUnsignedChar buffer) : this(Interop.EncodedImageBuffer.New(VectorUnsignedChar.getCPtr(buffer)), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) { throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } mCachedBuffer = buffer; }
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); }
/// <summary> /// Get VectorUnsignedChar from System.IO.Stream. /// This funcion exist only for Constructor. /// </summary> /// This will not be public opened. private static VectorUnsignedChar GetRawBuffrFromStreamHelper(System.IO.Stream stream) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } if (!stream.CanRead) { throw new InvalidOperationException("stream don't support to read"); } // Copy stream to memoryStream System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(); stream.CopyTo(memoryStream); memoryStream.Seek(0, System.IO.SeekOrigin.Begin); long streamLength = memoryStream.Length; if (streamLength <= 0) { throw new InvalidOperationException("stream length is <= 0"); } // 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 memoryStream to buffer System.Runtime.InteropServices.Marshal.Copy(memoryStream.GetBuffer(), 0, bufferRef.Handle, (int)streamLength); memoryStream.Dispose(); return(buffer); }