Esempio n. 1
0
        public static PixelBuffer LoadImageFromBuffer(System.IO.Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            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);

            PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.LoadImageFromBuffer(VectorUnsignedChar.getCPtr(buffer)), true);

            buffer.Dispose();
            if (NDalicPINVOKE.SWIGPendingException.Pending)
            {
                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Esempio n. 2
0
 internal EncodedImageBuffer(VectorUnsignedChar buffer) : this(Interop.EncodedImageBuffer.New(VectorUnsignedChar.getCPtr(buffer)), true)
 {
     if (NDalicPINVOKE.SWIGPendingException.Pending)
     {
         throw NDalicPINVOKE.SWIGPendingException.Retrieve();
     }
     mCachedBuffer = buffer;
 }