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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:21:54+00:00 2026-05-23T07:21:54+00:00

I’m trying to build this class (to use in ASP.NET site) that will Crop

  • 0

I’m trying to build this class (to use in ASP.NET site) that will Crop Image given custom Width,Height X,Y, then take the result image and Scale it to Custom Width, Height, And save in directory on the server return url of this image.

And i will get these paramerts in querystring like this

Default.aspx?x=100&y=300&w=800&h=500&scalew=160&scaleh=100 

So this is what i got so far

    public static Image CustomCrop(int width, int height, int x, int y, int scalwidth, int scalheight)
    {
        try
        {
            Image image = Image.FromFile("Images/none.jpg");
            Bitmap bmp = new Bitmap(width, height, 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, width, height), x, y, width, height, GraphicsUnit.Pixel);


            return bmp;
        }
        catch (Exception ex)
        {
            //MessageBox.Show(ex.Message);
            return null;
        }
    }

I will send these values Crop Image (width, height, x, y) then Scale the Croped image (scalwidth, scalheight) then save jpg in directory and return url for the image location

So what is the best way to this?

  • 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-23T07:21:54+00:00Added an answer on May 23, 2026 at 7:21 am

    Create a Generic Handler (i.e. ashx file) in your asp.net website or application, and place the following code inside it. Call it for example “Handler.ashx”.

    Now, in the browser use: Handler.ashx?x=100&y=300&w=800&h=500&scalew=160&scaleh=100

    Code of Handler.ashx file:

    <%@ WebHandler Language="C#" Class="Handler" %>
    
    using System;
    using System.Web;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Imaging;
    
    public class Handler : IHttpHandler {
    
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "image/jpeg";
            int x = int.Parse(context.Request["x"]);
            int y = int.Parse(context.Request["y"]);
            int h = int.Parse(context.Request["h"]);
            int w = int.Parse(context.Request["w"]);
            int scalew = int.Parse(context.Request["scalew"]);
            int scaleh = int.Parse(context.Request["scaleh"]);
            using (Image img = CustomCrop(w, h, x, y, scalew, scaleh))
                img.Save(context.Response.OutputStream,ImageFormat.Jpeg); 
        }
    
        public static Image CustomCrop(int width, int height, int x, int y, int scalwidth, int scalheight)
        {
            try
            {
                Image image = Image.FromFile("c:\\x.jpg");
                Bitmap bmp = new Bitmap(scalwidth, scalheight, 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, scalwidth, scalheight), x, y, width, height, GraphicsUnit.Pixel);
    
    
                return bmp;
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                return null;
            }
        }
        public bool IsReusable {
            get {
                return false;
            }
        }
    
    }
    

    EDIT:

    Some reference about Generic Handlers:

    HTTP Handlers and HTTP Modules Overview

    @ WebHandler – how ashx files work.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.