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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:32:55+00:00 2026-05-22T00:32:55+00:00

I want to crop an image retrieved from the database. I found the following

  • 0

I want to crop an image retrieved from the database. I found the following code on the net but it is in vb. I am doing asp.net c# based web page and i have no idea about vb

Can anyone take pain to give me the C# code to the following vb code?

help is highly appreciable and i would be very much thankful to you.

Here is the code:

  Dim ImageURL As String = "/Uploads/Gallery/" + ImageID + ".jpg"

        Dim oBitmap As New Bitmap(Server.MapPath(ImageURL))

        Dim Ratio As Integer = oBitmap.Width / 572


        Try

            Dim X1, Y1, X2, Y2, Width, Height As Integer

            Try
                X1 = x1txt.Text
                Y1 = y1txt.Text
                X2 = x2txt.Text
                Y2 = y2txt.Text
                Width = widthtxt.Text
                Height = heighttxt.Text
            Catch
            End Try

            X1 = X1 * Ratio
            Y1 = Y1 * Ratio
            X2 = X2 * Ratio
            Y2 = Y2 * Ratio
            Width = Width * Ratio
            Height = Height * Ratio

            Dim TopLeft As New Point(X1, Y1)
            Dim BottomRight As New Point(CInt(X1) + CInt(Height), CInt(Y1) + CInt(Width))

            Dim BitmapToSave As New Bitmap(oBitmap.Width, oBitmap.Height)

            Dim objGraphics As System.Drawing.Graphics
            objGraphics = System.Drawing.Graphics.FromImage(BitmapToSave)
            objGraphics.DrawImage(oBitmap, 0, 0)

            oBitmap.Dispose()

            BitmapToSave = img.CropImage(BitmapToSave, TopLeft, BottomRight)

            BitmapToSave.Save(Server.MapPath(ImageURL))

            BitmapToSave.Dispose()

        Catch
        End Try
  • 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-22T00:32:56+00:00Added an answer on May 22, 2026 at 12:32 am

    You can use this convertor: Convert VB.NET to C#

    string ImageURL = "/Uploads/Gallery/" + ImageID + ".jpg";
    
    Bitmap oBitmap = new Bitmap(Server.MapPath(ImageURL));
    
    int Ratio = oBitmap.Width / 572;
    
    
    
    try {
        int X1 = 0;
        int Y1 = 0;
        int X2 = 0;
        int Y2 = 0;
        int Width = 0;
        int Height = 0;
    
        try {
            X1 = x1txt.Text;
            Y1 = y1txt.Text;
            X2 = x2txt.Text;
            Y2 = y2txt.Text;
            Width = widthtxt.Text;
            Height = heighttxt.Text;
        } catch {
        }
    
        X1 = X1 * Ratio;
        Y1 = Y1 * Ratio;
        X2 = X2 * Ratio;
        Y2 = Y2 * Ratio;
        Width = Width * Ratio;
        Height = Height * Ratio;
    
        Point TopLeft = new Point(X1, Y1);
        Point BottomRight = new Point(Convert.ToInt32(X1) + Convert.ToInt32(Height), Convert.ToInt32(Y1) + Convert.ToInt32(Width));
    
        Bitmap BitmapToSave = new Bitmap(oBitmap.Width, oBitmap.Height);
    
        System.Drawing.Graphics objGraphics = null;
        objGraphics = System.Drawing.Graphics.FromImage(BitmapToSave);
        objGraphics.DrawImage(oBitmap, 0, 0);
    
        oBitmap.Dispose();
    
        BitmapToSave = img.CropImage(BitmapToSave, TopLeft, BottomRight);
    
        BitmapToSave.Save(Server.MapPath(ImageURL));
    
        BitmapToSave.Dispose();
    
    } catch {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to crop a photo retrieved from database, i have done the following
I want to crop Red part from following image, Is there any simple method
I would like to crop an image but I want to retain the part
The code below crops the image well, which is what i want, but for
I have an image .I want to crop 10 px from left and 10px
I want to crop an image from a specific row onwards. Please help me
I want to crop an image from the center in the size 200 *
Given any arbitrary image, I want to crop a square from the center of
I want to crop an image in my application when it is selected from
I want to crop an image. Is it possible to do like this. And

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.