Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WriteableBitmap wrBitmap;
- BitmapData bdata = new BitmapData();
- void Test(Stream stream)
- {
- var gdipBitmap = new Bitmap(stream);
- var width = gdipBitmap.Width;
- var height = gdipBitmap.Height;
- if (wrBitmap == null || height != wrBitmap.PixelHeight || width != wrBitmap.PixelWidth)
- {
- wrBitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Pbgra32, null);
- display.Source = wrBitmap;
- }
- wrBitmap.Lock();
- bdata.Width = width;
- bdata.Height = height;
- bdata.PixelFormat = System.Drawing.Imaging.PixelFormat.Format32bppArgb;
- bdata.Scan0 = wrBitmap.BackBuffer;
- bdata.Stride = wrBitmap.BackBufferStride;
- gdipBitmap.UnlockBits(gdipBitmap.LockBits(
- new System.Drawing.Rectangle(0, 0, bdata.Width, bdata.Height),
- ImageLockMode.ReadOnly | ImageLockMode.UserInputBuffer,
- System.Drawing.Imaging.PixelFormat.Format32bppArgb,
- bdata));
- wrBitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
- gdipBitmap.Dispose();
- wrBitmap.Unlock();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement