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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:14:31+00:00 2026-05-12T12:14:31+00:00

How can i compress and image file(*bmp,*jpeg) in C#, I have to display some

  • 0

How can i compress and image file(*bmp,*jpeg) in C#,
I have to display some images as background on my controls, i m using following code to scale my image

Bitmap orgBitmap = new Bitmap(_filePath);
Bitmap regBitmap = new Bitmap(reqSize.Width, reqSize.Height);

 using (Graphics gr = Graphics.FromImage(reqBitmap))
 {
  gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
  gr.DrawImage(bmp, new RectangleF(0, 0, reqSize.Width, reqSize.Height));
  }

It giving me the required bitmap.
My problem is if orginal bitmap is to heavy(2 MB) then when i load 50 image it feed all my memory, i want to compress the image as much i can without losing the so much quality,How can i do the same in .NET ?

  • 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-12T12:14:31+00:00Added an answer on May 12, 2026 at 12:14 pm

    Do you definitely need the large images to be present at execution time? Could you resize them (or save them at a slightly lower quality) using an image editing program (Photoshop, Paintshop Pro etc) beforehand? There seems to be little point in doing the work every time you run – especially as editing tools are likely to do a better job anyway.

    Of course, this won’t work if it’s something like the user picking arbitrary images from their hard disk.

    Another point: are you disposing of the bitmaps when you’re finished with them? You aren’t showing that in your code… if you’re not disposing of the original (large) bitmaps then you’ll be at the mercy of finalizers to release the unmanaged resources. The finalizers will also delay garbage collection of those objects.

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

Sidebar

Related Questions

Im using the following code to fetch image from a file,create an image list
I look for tool which can compress JavaScript source code. I found some web
I want to compress an image using JPEG encoder and instead of writing it
I have the following code to save an image to the cache directory of
I have trouble with saving images on sd card. I can see the file
The code Bitmap bmp = (Bitmap)extras.get(data); ByteArrayOutputStream out = new ByteArrayOutputStream(); bmp.compress(CompressFormat.JPEG, 100, out);
The code below get image from some location - and make this image compress
Using the System.IO.Compression namespaces classes GZIPStream and DeflateStream I successfully can compress and decompress
I wrote some code to save images on the SD Card a while back.
I am using the following code to take a screenshot of a TableLayout. 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.