PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Jul 20, 2018 2:48 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Mar 07, 2018 5:09 pm 
Offline

Joined: Wed Mar 07, 2018 4:57 pm
Posts: 2
Using PDFsharp NuGet v1.32.3057.0 on a windows form application.

I'm trying to figure out how I can define an XRect and tile an XImage all the way to bottom. If the image goes past the bottom of the rectangle, I want it to cut the image off at the bottom of the rectangle.

So right now, I have the tiling portion done. I can't figure out how to use the image transformations to cut the image off.

Tiling portion -
Code:
XRect graphicRect = newXRect(topLeftPt, bottomRightPt);

double imageY;
double width = scale * image.PointWidth;
double height = scale * image.PointHeight;

for (imageY = 0; imageY < graphicRect.Height - height; imageY += height)
{
    gfx.DrawImage(image, graphicRect.X, graphicRect.Y + imageY, width, height);
}


After this, I have the line
Code:
gfx.DrawImage(image, graphicRect.X, graphicRect.Y + imageY, width, graphicRect.Height - imageY);


This skews the image dimensions to fit the remaining space. What I'd like to do is just cut the rest of the image off after the bottom of the rectangle has been reached. Does anyone know how to accomplish this?


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 07, 2018 5:56 pm 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2829
Location: Cologne, Germany
Hi!

Here's what I would try: Draw the full image, but use a path to clip it.

See also:
http://www.pdfsharp.net/wiki/Graphics-s ... gh_path_16

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 07, 2018 6:16 pm 
Offline

Joined: Wed Mar 07, 2018 4:57 pm
Posts: 2
Thomas Hoevel wrote:
Hi!

Here's what I would try: Draw the full image, but use a path to clip it.

See also:
http://www.pdfsharp.net/wiki/Graphics-s ... gh_path_16


Thanks for the suggestion Thomas. I have it functioning properly now, below is my solution for any people who struggle with this in the future.

Code:
            XRect graphicRect = new XRect(topLeftGraphicPt, bottomRightGraphicPt);
            double imageY;
            double scale = 21 / image.PointWidth;
            double width = scale * image.PointWidth;
            double height = scale * image.PointHeight;
                   
            for (imageY = 0; imageY < graphicRect.Height - height; imageY += height)
            {
                  gfx.DrawImage(image, graphicRect.X, graphicRect.Y + imageY, width, height);
            }
            DrawGraphic(gfx, image, graphicRect, imageY, width, height);


Where the DrawGraphic method is -

Code:
        private static void DrawGraphic(XGraphics gfx, XImage image, XRect rect, double imageY, double width, double height)
        {
            gfx.Save();
            XGraphicsPath clipPath = new XGraphicsPath();
            clipPath.AddRectangle(rect);
            gfx.IntersectClip(clipPath);
            gfx.DrawImage(image, rect.X, rect.Y + imageY, width, height);
            gfx.Restore();
        }


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group