private IBitmap <ColorAlpha8> CreateMaskBitmap() { IBitmap <ColorAlpha8> dstMask = BitmapAllocator.Alpha8.Allocate(this.Size, AllocationOptions.Default); this.OnRender(dstMask); IBitmapLock <ColorAlpha8> keepAlive = dstMask.Lock <ColorAlpha8>(BitmapLockOptions.Read); return(new SharedBitmap <ColorAlpha8>(keepAlive, keepAlive.Size, keepAlive.Scan0, keepAlive.Stride, 96.0, 96.0)); }
private bool TryUpdateDeviceBitmap(int tileColumn, int tileRow) { IRenderTarget renderTarget = this.canvasView.RenderTarget; if (renderTarget == null) { return(false); } bool flag = renderTarget.IsSupported(RenderTargetType.Software, null, null, null); if (!flag && (!this.IsVisible || !this.IsActive)) { throw new PaintDotNet.InternalErrorException(); } if (!this.isDeviceBitmapCurrent[tileRow][tileColumn]) { using (IBitmap <ColorPbgra32> bitmap = this.tileCache.TryGetTileBufferRef(tileColumn, tileRow)) { if (bitmap != null) { if (bitmap.IsDisposed) { throw new ObjectDisposedException("tileBufferRef"); } if (flag) { DisposableUtil.Free <IDeviceBitmap>(ref this.deviceBitmaps[tileRow][tileColumn]); DisposableUtil.Free <IBitmap <ColorPbgra32> >(ref this.tileBuffers[tileRow][tileColumn]); IBitmapLock bitmapLock = bitmap.Lock <ColorPbgra32>(BitmapLockOptions.Read); IDeviceBitmap bitmap2 = renderTarget.CreateSharedBitmap(bitmapLock, null); this.deviceBitmaps[tileRow][tileColumn] = bitmap2; this.tileBuffers[tileRow][tileColumn] = bitmap.CreateRef <ColorPbgra32>(); } else { ObjectPoolTicket <IDeviceBitmap> ticket = this.deviceBitmapTickets[tileRow][tileColumn]; if (ticket == null) { try { ticket = this.owner.DeviceBitmapPool.Get(bitmap.Size); } catch (RecreateTargetException) { return(false); } this.deviceBitmapTickets[tileRow][tileColumn] = ticket; this.deviceBitmaps[tileRow][tileColumn] = ticket.Value; } ticket.Value.CopyFromBitmap(null, bitmap, null); } this.isDeviceBitmapCurrent[tileRow][tileColumn] = true; } } } return(true); }
private IBitmap CreateBitmap() { SizeInt32 size = this.Size; IBitmap <ColorPbgra32> bitmap = BitmapAllocator.Pbgra32.Allocate(size, AllocationOptions.Default); using (IBitmapLock <ColorPbgra32> @lock = bitmap.Lock <ColorPbgra32>(BitmapLockOptions.Write)) { using (System.Drawing.Bitmap bitmap2 = new System.Drawing.Bitmap(size.Width, size.Height, @lock.Stride, System.Drawing.Imaging.PixelFormat.Format32bppPArgb, @lock.Scan0)) { using (Graphics graphics = Graphics.FromImage(bitmap2)) { this.Draw(graphics); } } } return(bitmap); }
private IDeviceBitmap InitializeDeviceBitmap(IDeviceResourceFactory factory, IBitmap bitmap, ref IDeviceBitmap deviceBitmap) { if (bitmap == null) { this.ReturnOrFreeDeviceBitmap(ref deviceBitmap); return(deviceBitmap); } if ((bitmap != null) && (deviceBitmap == null)) { if (factory.IsSupported(RenderTargetType.Software, null, null, null)) { SizeInt32 num = bitmap.Size; IBitmapLock bitmapLock = bitmap.Lock(BitmapLockOptions.Read); deviceBitmap = factory.CreateSharedBitmap(bitmapLock, new BitmapProperties?(maskBitmapProperties)); return(deviceBitmap); } SizeInt32 size = bitmap.Size; deviceBitmap = this.GetOrCreateDeviceBitmap(factory, size); deviceBitmap.CopyFromBitmap(new PointInt32?(PointInt32.Zero), bitmap, new RectInt32(PointInt32.Zero, size)); } return(deviceBitmap); }
/// <summary> /// Locks the data of the image to directly access the bytes of the image /// </summary> /// <remarks> /// This locks the data to read and write to directly using unsafe pointers. After reading or updating /// the data, you must call <see cref="Unlock"/> to unlock the data. /// </remarks> /// <returns>A <see cref="BitmapData"/> object with information about the locked data</returns> public BitmapData Lock() { return(handler.Lock()); }