Reputation: 1249
I am using PDFsharp to make a PDF file, and have succeeded to put an image on my page.
byte[] imgBytes = interview.Application.CandidateImage.ImageBinary.ToArray();
Stream stream = new MemoryStream(imgBytes);
MemoryStream strm = new MemoryStream();
System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
img.Save(strm, System.Drawing.Imaging.ImageFormat.Png);
XImage xfoto = XImage.FromGdiPlusImage(img);
gfx.DrawImage(xfoto, 30, 130, 300, 300);
This gets the binary image data and the DrawImage will draw this image retrieved from the stream.
The thing is, I want to make the image round just as if I used img-circle class on HTML. Is there a function for this with PDFsharp? If not, how can I do this?
EDIT:
void DrawClipPath(XGraphics gfx, PdfPage page)
{
XGraphicsPath path = new XGraphicsPath();
path.AddEllipse((page.Width / 2) - 150, (page.Height / 2) - 120, 300, 300);
gfx.Save();
gfx.IntersectClip(path);
// Draw a beam of dotted lines
XPen pen = XPens.DarkRed.Clone();
pen.DashStyle = XDashStyle.Dot;
for (double r = 0; r <= 90; r += 0.5)
gfx.DrawLine(pen, 0, 0, 250 * Math.Cos(r / 90 * Math.PI), 250 * Math.Sin(r / 90 * Math.PI));
gfx.Restore();
}
Upvotes: 0
Views: 2330
Reputation: 5834
You can set a circle as a clip path and then draw the image. You have to save the graphic state (XGraphics.Save) before setting the clip path and then restore it (XGraphics.Restore) after you drew all the objects that needed to be clipped.
EDIT: I'm not familiar with PDFSharp API but the code would look something like this:
gfx.Save();
XGraphicsPath clipPath = new XGraphicsPath();
clipPath.AddEllipse(30, 130, 300, 300);
gfx.IntersectClip(clipPath);
gfx.DrawImage(xfoto, 30, 130, 300, 300);
gfx.Restore();
Upvotes: 2
Reputation: 21729
You can use images with transparency so that only the round part in the centre is visible.
Or use a hack: draw the image first, then draw a white mask over the image, leaving just the round part in the centre showing.
Upvotes: 1