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

  • SEARCH
  • Home
  • 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 7849251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:27:31+00:00 2026-06-02T18:27:31+00:00

I have a image that I want to crop it when I press a

  • 0

I have a image that I want to crop it when I press a button on the form. I have the following code that is run when the button is pressed, but it doesn’t do anything to the image:

try
{
  Image image = Image.FromFile("test.jpg");
  Bitmap bmp = new Bitmap(200, 200, PixelFormat.Format24bppRgb);
  bmp.SetResolution(80, 60);

  Graphics gfx = Graphics.FromImage(bmp);
  gfx.SmoothingMode = SmoothingMode.AntiAlias;
  gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
  gfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
  gfx.DrawImage(image, new Rectangle(0, 0, 200, 200), 10, 10, 200, 200, GraphicsUnit.Pixel);
  // Dispose to free up resources
  image.Dispose();
  bmp.Dispose();
  gfx.Dispose();
}
catch (Exception ex)
{
  MessageBox.Show(ex.Message);
}     

My image is actually a screenshot of the active window of the form with the following code:

Rectangle bounds = this.Bounds;
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
  using (Graphics g = Graphics.FromImage(bitmap))
  {
    g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
  }
  bitmap.Save("test.jpg", ImageFormat.Jpeg);
}

To finish this, at the press of the same button, first I want to take the screenshot of the form, then crop that image, but cropping doesn’t work. Why is that?

  • 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-02T18:27:31+00:00Added an answer on June 2, 2026 at 6:27 pm

    Your code is close to what I have been using for saving cropped images. You’re missing the part where you save the cropped image. You need to write the cropped image to a byte stream then save it to disk. I modified your code, it’s untested but give it a try.

    try
    {
        Image image = Image.FromFile("test.jpg");
        Bitmap bmp = new Bitmap(200, 200, PixelFormat.Format24bppRgb);
        bmp.SetResolution(80, 60);
    
        Graphics gfx = Graphics.FromImage(bmp);
        gfx.SmoothingMode = SmoothingMode.AntiAlias;
        gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
        gfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
        gfx.DrawImage(image, new Rectangle(0, 0, 200, 200), 10, 10, 200, 200, GraphicsUnit.Pixel);
    
        //Need to write the file to memory then save it
        MemorySteam ms = new MemoryStream();
        bmp.Save(ms, image.RawFormat); 
        byte[] buffer = ms.GetBuffer();
    
        var stream = new MemorySteam((buffer), 0, buffer.Length); 
        var croppedImage = SD.Image.FromStream(steam, true);
        croppedImage.Save("/your/path/image.jpg", croppedImage.RawFormat);
    
        // Dispose to free up resources
        image.Dispose();
        bmp.Dispose();
        gfx.Dispose();
        stream.Dispose();
        croppedImage.Dispose();
    
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have done zooming of an image. now I want to crop that zoomed
I have an image that I want to position in the right and repeat
I have an image that I want to resize on my websites rendering using
I have an image that I want to move. I can move the element
I am using GWT 2.03 and am have an image that I want to
I have an image that is too big and I want to put it
I have emoticons in a css sprite image that I want to display within
I have a 16 bit grayscale image that I want to display using WPF
I want to be able to take an image that i have already captured
I have a page http://www.mysite.com/image.aspx , that I want to load and display an

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.