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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:45:59+00:00 2026-05-26T09:45:59+00:00

I need to do two things to an image: resize it, then crop it.

  • 0

I need to do two things to an image: resize it, then crop it.

I’m resizing like this:

nonResizedImage = new Bitmap(imagePath);
Bitmap scaled = new Bitmap(preCropWidth, preCropHeight);
using (Graphics scaledGraphics = Graphics.FromImage(scaled)) 
{ // scale image to the sizeo f the image the user cropped on
    scaledGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
    scaledGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
    scaledGraphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
    scaledGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
    scaledGraphics.Clear(ColorTranslator.FromHtml("#FFFFFF"));
    scaledGraphics.DrawImage(nonResizedImage, 0, 0, preCropWidth, preCropHeight);
}

Now I need to crop the image. I’ve found a function that does this:

static byte[] Crop(string Img, int Width, int Height, int X, int Y)
{
    try
    {
        using (SD.Image OriginalImage = SD.Image.FromFile(Img))
        {
            using (SD.Bitmap bmp = new SD.Bitmap(Width, Height))
            {
                bmp.SetResolution(OriginalImage.HorizontalResolution, OriginalImage.VerticalResolution);

                using (SD.Graphics Graphic = SD.Graphics.FromImage(bmp))
                {
                    Graphic.SmoothingMode = SmoothingMode.AntiAlias;
                    Graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    Graphic.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    Graphic.DrawImage(OriginalImage, new SD.Rectangle(0, 0, Width, Height), X, Y, Width, Height, SD.GraphicsUnit.Pixel);
                    MemoryStream ms = new MemoryStream();
                    bmp.Save(ms, OriginalImage.RawFormat);
                    return ms.GetBuffer();
                }
            }
        }
    }

    catch (Exception Ex)
    {
        throw Ex;
    }
}

But this requires a image as input. So, I could save the output of my resize code to the disk, then read it back in again to do the crop, but this seems needlessly inefficient. I don’t really know much about image manipulation in c# though.

How do I crop the scaledGraphics I have, without first saving it to the disk?

  • 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-26T09:45:59+00:00Added an answer on May 26, 2026 at 9:45 am

    One of the overloads for new Bitmap is Width, Height, Graphics Object. You should be able to just pass the graphics object in and then create the bitmap from that. Something like this

      static byte[] Crop(Graphics g, int Width, int Height, int X, int Y)
      {
          try
           {
              using (Bitmap bmp = new Bitmap(Width, Height, g))
              { 
               ...
              }
            }
            ......
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need two divs to look a bit like this: | | ---| LOGO
I have a list of two-item lists and need to search for things in
I need UNION two tables with creating new field, where 1 for first table,
I need to process large image files into smaller image files. I would like
this site is like an ecommerce site and i have two tables that i'm
I need two things to be done: Create a video from the images (jpeg)
I'm trying to do two things -> First I need to read in an
I need two methods one to encrypt and one to decrypt an xml file
I need two tables and two sets of fields, not the name of the
Why do I need two of them? When I have to use one or

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.