/* An example figure that show how one can use the CompositingMode * to do a decent alpha blend. * However this is a bit slower and does not blend the edges of the * bitmap with the canvas when AntiAlias is turned on. * * Needs more work/thinking... */ protected override void PaintBody(DGraphics dg) { if (Width > 0 && Height > 0) { DBitmap bmp = GraphicsHelper.MakeBitmap(Width, Height); DGraphics bmpGfx = GraphicsHelper.MakeGraphics(bmp); bmpGfx.AntiAlias = dg.AntiAlias; bmpGfx.CompositingMode = DCompositingMode.SourceCopy; bmpGfx.FillRect(1, 1, Width - 2, Height - 2, DColor.Blue, Alpha); bmpGfx.FillRect(1, 1, 2 * Width / 3, 2 * Height / 3, DColor.Red, Alpha); bmpGfx.FillRect(Width / 3, Height / 3, 2 * Width / 3 - 1, 2 * Height / 3 - 1, DColor.Green, Alpha); dg.DrawBitmap(bmp, Rect, Alpha); bmpGfx.Dispose(); bmp.Dispose(); } }
public override void Paint(DGraphics dg, Figure f, double scale) { dg.DrawBitmap(bmp, GetRect(Position, f.GetSelectRect(), scale)); }
protected override void PaintBody(DGraphics dg) { if (Bitmap != null) { dg.Save(); dg.Clip(Rect); switch (BitmapPosition) { case DBitmapPosition.Stretch: dg.DrawBitmap(Bitmap, Rect, Alpha); break; case DBitmapPosition.Normal: dg.DrawBitmap(Bitmap, TopLeft, Alpha); break; case DBitmapPosition.Center: dg.DrawBitmap(Bitmap, new DPoint(X + Width / 2 - Bitmap.Width / 2, Y + Height / 2 - Bitmap.Height / 2), Alpha); break; case DBitmapPosition.Tile: int xTimes = (int)Math.Ceiling(Width / Bitmap.Width); int YTimes = (int)Math.Ceiling(Height / Bitmap.Height); for (int i = 0; i < xTimes; i++) for (int j = 0; j < YTimes; j++) dg.DrawBitmap(Bitmap, new DPoint(X + i * Bitmap.Width, Y + j * Bitmap.Height), Alpha); break; case DBitmapPosition.StretchWithAspectRatio: double sx = Width / Bitmap.Width; double sy = Height / Bitmap.Height; DRect bmpRect; if (sx > sy) { double w = sy * Bitmap.Width; bmpRect = new DRect(X + Width / 2 - w / 2, Y, w, Height); } else { double h = sx * Bitmap.Height; bmpRect = new DRect(X, Y + Height / 2 - h / 2, Width, h); } dg.DrawBitmap(Bitmap, bmpRect, Alpha); break; } dg.Restore(); } }