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 7544003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:34:25+00:00 2026-05-30T08:34:25+00:00

I have written a small application which will be used in my work environment

  • 0

I have written a small application which will be used in my work environment for cropping images. The windows form (.NET 3.5) that contains the image has a transparent rectangle which I use for dragging over a section of an image and hitting a button to get me whatever was behind the rectangle.

Currently I am using the code below, this is causing me issues because the area that it is capturing is off by quite a few pixels, and I think it’s something to do with my CopyFromScreen function.

    //Pass in a rectangle
    private void SnapshotImage(Rectangle rect)
    {
        Point ptPosition = new Point(rect.X, rect.Y);
        Point ptRelativePosition;

        //Get me the screen coordinates, so that I get the correct area
        ptRelativePosition = PointToScreen(ptPosition);

        //Create a new bitmap
        Bitmap bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);

        //Sort out getting the image
        Graphics g = Graphics.FromImage(bmp);

        //Copy the image from screen
        g.CopyFromScreen(this.Location.X + ptPosition.X, this.Location.Y + ptPosition.Y,   0,  0, bmp.Size, CopyPixelOperation.SourceCopy);
        //Change the image to be the selected image area
        imageControl1.Image.ChangeImage(bmp);  
    }

If anyone can spot why when the image is redrawn its quite a bit out, I’d be eternally grateful at this point. Also, the ChangeImage function is fine – it works if I use a form as a select area but using a rectangle has jazzed things up a bit.

  • 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-05-30T08:34:26+00:00Added an answer on May 30, 2026 at 8:34 am

    Interestingly, this was because of the space between the main form and the control that the image was on and the toolbar at the top of the form separating the control and the top of the main form. To get around this I simply modified one line in capture screen to account for those pixels, as shown below:

    g.CopyFromScreen(relativePosition.X + 2, relativePosition.Y+48,  Point.Empty.X, Point.Empty.Y, bmp.Size);
    

    Cheers

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

Sidebar

Related Questions

I have written a small .net Windows Forms application. And now I decided to
i have written a small form application, which contains textbox only. I have enabled
I have written a small java application for which I need to obtain performance
I have a small AJAX application, written in PHP that I did not secure
I have a small command-line application written in C that acts as a wrapper/launcher
I have written a small jquery application that allows a person to slide a
I have a small linux vps. I have written a Java client application, which
I have written a really small 64-bit application that crashes on clean installations of
We have a small daemon application written in C for a couple of various
I have written a small chat app that uses mysql + php to facilitate

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.