Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8261061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:16:22+00:00 2026-06-08T03:16:22+00:00

My problem is with clipping an image via GraphicsPath. I have a fairly complex

  • 0

My problem is with clipping an image via GraphicsPath. I have a fairly complex clipping path (composed of various arcs) and I need to save only that part of the image that is within this path.

I have a class like this:

class A 
{
    private GraphicsPath GetGraphicsPath()
    { 
        ... some stuff ...
        return gp;
    }

    public void Draw(Graphics g)
    {
         g.DrawPath(pen, GetGraphicsPath());
    }

    public Save(Image img, string fileName)
    {
        Bitmap b = new Bitmap(img.Width, img.Height);
        Graphics bg = Graphics.FromImage(b);
        bg.Clip = new Region(GetGraphicsPath());
        bg.DrawImage(img, 0, 0);
        b.Save(fileName + ".png");
    }
}

and then I have a form with a panel pnMain, with a background image. I have two buttons with the following functions:

    private void button1_Click(object sender, EventArgs e)
    {
        Graphics g = pnMain.CreateGraphics();
        a.Draw(g);
    }

    private void button2_Click(object sender, EventArgs e)
    {
        Image img = pnMain.BackgroundImage;
        a.Save(img, "test");
    }

(in both cases a is an instance of A). My problem is that the clipping region drawn on screen (using first button and method Draw) is what I would like to save, however, the clipped image saved through second button and method Save is distorted, smaller and shifted. What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:16:26+00:00Added an answer on June 8, 2026 at 3:16 am

    I figured it out — it is the resolution of the background image in the panel. The properties HorizontalResolution and VerticalResolution of the Bitmap img have to match the DPIX and DPIY properties of the Graphics. I did not found out how to set any of these via C#, but I was able to change the resolution of the bitmap in Photoshop and now everything works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: I have a table that prints out vertical but I would like it
Problem: I have two array where one produce a category and the second produce
Problem Using Director 11.5 and Windows 7, with MouseWheel Xtra (wheelmouse.zip), I have the
I have a problem with lighting in my OpenGL application. When one of the
Problem: I need an array (datamember) in a parent class A. However, depending on
Problem Description: We have a service which has applications for main mobile OS’s. We
I have a problem just with rendering a simple rotating cube with SlimDX (DirectX
I've been struggling with a clipping problem with a window with non-zero window origin
I am trying to animate a clipping path. I read from Mask Animations (Clipping
Problem I need to replace all asterisk symbols('*') with percent symbol('%'). The asterisk symbols

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.