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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:47:25+00:00 2026-05-10T21:47:25+00:00

I am currently writing a system that stores meta data for around 140,000 ish

  • 0

I am currently writing a system that stores meta data for around 140,000 ish images stored within a legacy image library that are being moved to cloud storage. I am using the following to get the jpg data…

System.Drawing.Image image = System.Drawing.Image.FromFile('filePath'); 

Im quite new to image manipulation but this is fine for getting simple values like width, height, aspect ratio etc but what I cannot work out is how to retrieve the physical file size of the jpg expressed in bytes. Any help would be much appreciated.

Thanks

Final solution including an MD5 hash of the image for later comparison

System.Drawing.Image image = System.Drawing.Image.FromFile(filePath);  if (image != null) {   int width = image.Width;   int height = image.Height;   decimal aspectRatio = width > height ? decimal.divide(width, height) : decimal.divide(height, width);     int fileSize = (int)new System.IO.FileInfo(filePath).Length;    using (System.IO.MemoryStream stream = new System.IO.MemoryStream(fileSize))   {     image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);     Byte[] imageBytes = stream.GetBuffer();     System.Security.Cryptography.MD5CryptoServiceProvider provider = new System.Security.Cryptography.MD5CryptoServiceProvider();     Byte[] hash = provider.ComputeHash(imageBytes);      System.Text.StringBuilder hashBuilder = new System.Text.StringBuilder();      for (int i = 0; i < hash.Length; i++)     {       hashBuilder.Append(hash[i].ToString('X2'));     }      string md5 = hashBuilder.ToString();   }    image.Dispose();  } 
  • 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. 2026-05-10T21:47:25+00:00Added an answer on May 10, 2026 at 9:47 pm

    If you get your image directly from file, you can use the following code to get size of original file in bytes.

     var fileLength = new FileInfo(filePath).Length;  

    If you get your image from other source, like getting one bitmap and composing it with other image, like adding watermark you will have to calculate size in run-time. You can’t just use original file size, because compressing may lead to different size of output data after modification. In this case, you can use MemoryStream to save image to:

    long jpegByteSize; using (var ms = new MemoryStream(estimatedLength)) // estimatedLength can be original fileLength {     image.Save(ms, ImageFormat.Jpeg); // save image to stream in Jpeg format     jpegByteSize = ms.Length;  } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Brief history: I'm writing a stored procedure to support a legacy reporting system (using
I'm currently in the throes of writing a system based on subdividing space (it's
I am currently re-writing my functions script (PHP) for my login system. Is the
I'm currently writing a peer-to-peer chat application to chat around the world, but my
I am currently writing a simple, timer-based mini app in C# that performs an
I'm currently writing an interface to allow applications to send exception data to a
I'm currently writing a tool that parses the FxCop logfile on a large codebase.
When writing a Python script that can be executed in different operating system environments
I'm currently writing an N-Tier architected ASP.NET system with a relatively normalised SQL database
I am currently writing a system for publishing tutorials about basic PHP. However, 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.