示例#1
0
 private void SetResolution(uint bitmapWidth, uint bitmapHeight)
 {
     lock (updateLock)
     {
         if (map != IntPtr.Zero)
         {
             MemoryInternal.UnmapViewOfFile(map);
             map = IntPtr.Zero;
         }
         if (section != IntPtr.Zero)
         {
             MemoryInternal.CloseHandle(section);
             section = IntPtr.Zero;
         }
         uint imageSize = (uint)bitmapWidth * (uint)bitmapHeight;
         if (imageSize == 0x00)
         {
             return;
         }
         // create memory section and map
         section = MemoryInternal.CreateFileMapping(new IntPtr(-1), IntPtr.Zero, 0x04, 0, imageSize, null);
         map     = MemoryInternal.MapViewOfFile(section, 0xF001F, 0, 0, imageSize);
     }
     Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Render, (SendOrPostCallback) delegate
     {
         Bitmap = Imaging.CreateBitmapSourceFromMemorySection(section, (int)bitmapWidth, (int)bitmapHeight, PixelFormats.Gray8, (int)bitmapWidth, 0) as InteropBitmap;
         Bitmap.Invalidate();
         Source           = Bitmap;
         Stretch          = System.Windows.Media.Stretch.Fill;
         StretchDirection = StretchDirection.Both;
     }, null);
 }
示例#2
0
 private void Destroy()
 {
     lock (updateLock)
     {
         if (map != IntPtr.Zero)
         {
             MemoryInternal.UnmapViewOfFile(map);
             map = IntPtr.Zero;
         }
         if (section != IntPtr.Zero)
         {
             MemoryInternal.CloseHandle(section);
             section = IntPtr.Zero;
         }
     }
 }