Advertisement
Guest User

Untitled

a guest
Jun 20th, 2015
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. WriteableBitmap wrBitmap;
  2. BitmapData bdata = new BitmapData();
  3.  
  4. void Test(Stream stream)
  5. {
  6.     var gdipBitmap = new Bitmap(stream);
  7.     var width = gdipBitmap.Width;
  8.     var height = gdipBitmap.Height;
  9.     if (wrBitmap == null || height != wrBitmap.PixelHeight || width != wrBitmap.PixelWidth)
  10.     {
  11.         wrBitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Pbgra32, null);
  12.         display.Source = wrBitmap;
  13.     }
  14.     wrBitmap.Lock();
  15.     bdata.Width = width;
  16.     bdata.Height = height;
  17.     bdata.PixelFormat = System.Drawing.Imaging.PixelFormat.Format32bppArgb;
  18.     bdata.Scan0 = wrBitmap.BackBuffer;
  19.     bdata.Stride = wrBitmap.BackBufferStride;
  20.     gdipBitmap.UnlockBits(gdipBitmap.LockBits(
  21.         new System.Drawing.Rectangle(0, 0, bdata.Width, bdata.Height),
  22.         ImageLockMode.ReadOnly | ImageLockMode.UserInputBuffer,
  23.         System.Drawing.Imaging.PixelFormat.Format32bppArgb,
  24.         bdata));
  25.     wrBitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
  26.     gdipBitmap.Dispose();
  27.     wrBitmap.Unlock();
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement