Ejemplo n.º 1
0
 public static void Read(this Stream input, SafeHGlobalHandle buffer, long offset, int length)
 {
     try
     {
         using (UnmanagedMemoryStream output = new UnmanagedMemoryStream(buffer, 0, length, FileAccess.Write))
         {
             byte[] buff = new byte[Math.Min(32 * 1024, length)];
             input.CopyTo(output, length, buff);
         }
     }
     catch
     {
         buffer.Dispose();
         throw;
     }
 }
Ejemplo n.º 2
0
        public static SafeHGlobalHandle GetPixels(this BitmapSource self, out Int32Rect rect)
        {
            int size = self.PixelWidth * self.PixelHeight * self.Format.BitsPerPixel / 8;

            rect = new Int32Rect(0, 0, self.PixelWidth, self.PixelHeight);
            SafeHGlobalHandle buffer = new SafeHGlobalHandle(size);

            try
            {
                self.CopyPixels(rect, buffer.DangerousGetHandle(), size, size / self.PixelHeight);
                return(buffer);
            }
            catch
            {
                buffer.SafeDispose();
                throw;
            }
        }
Ejemplo n.º 3
0
        public static SafeHGlobalHandle ReadBuff(this Stream input, int size)
        {
            SafeHGlobalHandle handle = new SafeHGlobalHandle(size);

            try
            {
                using (UnmanagedMemoryStream output = new UnmanagedMemoryStream(handle, 0, size, FileAccess.Write))
                {
                    byte[] buff = new byte[Math.Min(32 * 1024, size)];
                    input.CopyTo(output, size, buff);
                }
            }
            catch
            {
                handle.Dispose();
                throw;
            }

            return(handle);
        }