public void DrawImageAlpha(float alpha, AbstractImage image, RectangleF targetRect) { if (alpha <= 0) { return; } if (alpha >= 1) { DrawImage(image, targetRect.X, targetRect.Y, targetRect.Width, targetRect.Height); return; } Image gdiImage = image.Image; lock (gdiImage) { ColorMatrix matrix = new ColorMatrix(); matrix.Matrix00 = matrix.Matrix11 = matrix.Matrix22 = 1; matrix.Matrix33 = alpha; ImageAttributes attr = new ImageAttributes(); attr.SetColorMatrix(matrix); PointF[] dest = new PointF[] { new PointF(targetRect.Left, targetRect.Top), new PointF(targetRect.Right, targetRect.Top), new PointF(targetRect.Left, targetRect.Bottom) }; g.DrawImage(gdiImage, dest, new RectangleF(0, 0, gdiImage.Width, gdiImage.Height), GraphicsUnit.Pixel, attr); } }
public void DrawImage(AbstractImage image, float x, float y, float width, float height) { var e = Append(new Element(ElementNames.IMAGE)); e.Set("x", x); e.Set("y", y); e.Set("width", width); e.Set("height", height); e.Set("xlink:href", image.Url); }
public void DrawImageAlpha(float alpha, AbstractImage image, RectangleF targetRect) { var e = Append(new Element(ElementNames.IMAGE)); e.Set("x", targetRect.X); e.Set("y", targetRect.Y); e.Set("width", targetRect.Width); e.Set("height", targetRect.Height); e.Set("opacity", alpha); e.Set("xlink:href", image.Url); }
public void DrawImage(AbstractImage image, float x, float y, float width, float height) { g.DrawImage(image.Image, x, y, width, height); }
public void DrawImageAlpha(float alpha, AbstractImage mimage, RectangleF targetRect) { // Clamp and Quantize alpha = Util.Clamp(alpha, 0f, 1f); alpha = (float)Math.Round(alpha * 16f) / 16f; if (alpha <= 0f) { return; } if (alpha >= 1f) { g.DrawImage(mimage.XImage, targetRect); return; } int key = (int)Math.Round(alpha * 16); Image image = mimage.Image; XImage ximage; int w, h; lock (image) { w = image.Width; h = image.Height; if (image.Tag == null || !(image.Tag is Dictionary <int, XImage>)) { image.Tag = new Dictionary <int, XImage>(); } Dictionary <int, XImage> dict = image.Tag as Dictionary <int, XImage>; if (dict.ContainsKey(key)) { ximage = dict[key]; } else { // Need to construct a new image (PdfSharp can't alpha-render images) // Memoize these in the image itself, since most requests will be from // a small set Bitmap scratchBitmap = new Bitmap(w, h, PixelFormat.Format32bppArgb); using (var scratchGraphics = Graphics.FromImage(scratchBitmap)) { ColorMatrix matrix = new ColorMatrix(); matrix.Matrix00 = matrix.Matrix11 = matrix.Matrix22 = 1; matrix.Matrix33 = alpha; ImageAttributes attr = new ImageAttributes(); attr.SetColorMatrix(matrix); scratchGraphics.DrawImage(image, new Rectangle(0, 0, w, h), 0, 0, w, h, GraphicsUnit.Pixel, attr); } ximage = XImage.FromGdiPlusImage(scratchBitmap); dict[key] = ximage; } } lock (ximage) { g.DrawImage(ximage, targetRect); } }