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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:04:51+00:00 2026-05-26T12:04:51+00:00

Below is the action method that returns images from the database as they are,

  • 0

Below is the action method that returns images from the database as they are, I need some lite library or write the code myself if short that will resize and compress these images according to my requirements “Make thumbnails” before they are passed to the HTTP response.

EDIT: Actually come to think of it, perhaps it would be best to save thumbnails in additional column, so now I need a way to compress and resize the images before they are saved to the database a long with saving a copy that is untouched. Saving images initially by passing them in HttpPostedFileBase and now need some tool that will resize and compress before saving to database.

public FileContentResult GetImage(int LineID)
{
    var PMedia = repository.ProductMedias.FirstOrDefault(x => x.LineID == LineID);

    if (PMedia != null)
    {
        return File(PMedia.ImageData, PMedia.ImageMimeType, PMedia.FileName);
    }
    else
    {
        return null;
    }
} 
  • 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-26T12:04:52+00:00Added an answer on May 26, 2026 at 12:04 pm

    Here is routine that I use for making thumbnails :

        public void MakeThumbnail(string imagePath)
        {
            // Image exists?
            if (string.IsNullOrEmpty(imagePath)) throw new FileNotFoundException("Image does not exist at " + imagePath);
    
            // Default values
            string Filename = imagePath.ToLower().Replace(".jpg", "_thumb.jpg");
            int Width = 100; // 180;
            int Height = 75; // 135;
            bool lSaved = false;
    
            // Load image
            Bitmap bitmap = new Bitmap(imagePath);
    
            // If image is smaller than just save
            try
            {
                if (bitmap.Width <= Width && bitmap.Height <= Height)
                {
                    bitmap.Save(Filename, ImageFormat.Jpeg);
                    lSaved = true;
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                bitmap.Dispose();
            }
    
            if (!lSaved)
            {
                Bitmap FinalBitmap = null;
                // Making Thumb
                try
                {
                    bitmap = new Bitmap(imagePath);
    
                    int BitmapNewWidth;
                    decimal Ratio;
                    int BitmapNewHeight;
    
                    // Change size of image
                    Ratio = (decimal)Width / Height;
                    BitmapNewWidth = Width;
                    BitmapNewHeight = Height;
    
                    // Image processing
                    FinalBitmap = new Bitmap(BitmapNewWidth, BitmapNewHeight);
                    Graphics graphics = Graphics.FromImage(FinalBitmap);
                    graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    graphics.FillRectangle(Brushes.White, 0, 0, BitmapNewWidth, BitmapNewHeight);
                    graphics.DrawImage(bitmap, 0, 0, BitmapNewWidth, BitmapNewHeight);
    
                    // Save modified image
                    FinalBitmap.Save(Filename, ImageFormat.Jpeg);
    
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
                finally
                {
                    if (FinalBitmap != null) FinalBitmap.Dispose();
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the code below I pass method B as an action to be perfomed
Below is the plugin code that i have tried to reuse from an old
I have an Action Method that I'd either like to return JSON from on
See the four lines in the Go() method below: delegate void Action<T>(T arg); delegate
In the method CreateView() (check my View Engine below) or in my custom action
I'm using a form containing a button type shown below: <form method=post action=> <button
I have divs that are initially closed. The code below then controls the opening/closing:
I want to forward request to a non-JSF page from JSF action method. I
I have some jQuery code in an external Javascript file that is making an
I've placed some very basic code below of what I'm trying to do. I

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.