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

  • Home
  • SEARCH
  • 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 7986837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:58:01+00:00 2026-06-04T11:58:01+00:00

I have a c# application that contains an image gallery where I display some

  • 0

I have a c# application that contains an image gallery where I display some pictures.
This gallery have some features including left and right rotation.
everything is perfect but when I choose a picture from gallery and press rotation button (regardless left or right rotation), size of the picture increase significantly.
It should be mentioned that the picture’s format is JPEG.

Size of picture before rotation : 278 kb

Size of picture after rotation : 780 kb

My code for rotation is like bellow :

 public Image apply(Image img)
    {  
        Image im = img;
        if (rotate == 1) im.RotateFlip(RotateFlipType.Rotate90FlipNone);
        if (rotate == 2) im.RotateFlip(RotateFlipType.Rotate180FlipNone);
        if (rotate == 3) im.RotateFlip(RotateFlipType.Rotate270FlipNone);

        //file size is increasing after RotateFlip method

        if (brigh != DEFAULT_BRIGH ||
            contr != DEFAULT_CONTR ||
            gamma != DEFAULT_GAMMA)
        {
            using (Graphics g = Graphics.FromImage(im))
            {
                float b = _brigh;
                float c = _contr;
                ImageAttributes derp = new ImageAttributes();
                derp.SetColorMatrix(new ColorMatrix(new float[][]{
                        new float[]{c, 0, 0, 0, 0},
                        new float[]{0, c, 0, 0, 0},
                        new float[]{0, 0, c, 0, 0},
                        new float[]{0, 0, 0, 1, 0},
                        new float[]{b, b, b, 0, 1}}));
                derp.SetGamma(_gamma);
                g.DrawImage(img, new Rectangle(Point.Empty, img.Size),
                    0, 0, img.Width, img.Height, GraphicsUnit.Pixel, derp);
            }
        }
        return im; 
    }

What is the problem?

  • 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-06-04T11:58:03+00:00Added an answer on June 4, 2026 at 11:58 am

    In your case applying RotateFlip on im is changing the ImageFormat from Jpeg to MemoryBmp.
    By Default when you save the image it is going to make use of the default ImageFormat. This will be the format returned by im.RawFormat

    if you check the GUID im.RawFormat.Guid

    Before RotateFlip

    {b96b3cae-0728-11d3-9d7b-0000f81ef32e}
    which is same as ImageFormat.Jpeg.Guid

    After RotateFlip

    {b96b3caa-0728-11d3-9d7b-0000f81ef32e}
    which is same as ImageFormat.MemoryBmp.Guid

    At the time of saving the image pass the ImageFormat as the second parameter which will ensure that it uses the correct format. If not mentioned it is going to be the one in im.RawFormat

    So If you want to save as jpeg at the time of saving call

    im.Save("filename.jpg", ImageFormat.Jpeg);
    

    This time the file size should be less than the original size.

    Also note ImageFormat is in System.Drawing.Imaging namespace

    NOTE

    To control the quality of the jpeg make use of the overloaded Save method as mentioned in this MSDN Link


    EDIT Based On Comment

    OK assuming you are using SQL Server you must be having a image datatype column (it is recommended to use varbinary(max) instead of image as in future it is going to be obselete (Read MSDN Post)

    Now to the steps

    1) read the contents as a stream / byte[] array
    
    2) convert this to Image
    
    3) perform rotate operation on the Image
    
    4) convert this Image back to stream / byte[] array
    
    5) Update the database column with the new value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want my WPF application to have a ToggleButton that contains an image of
I have a .NET application that contains a checkbox (System.Windows.Forms.Checkbox). This component (WindowsForms10.BUTTON.app.0.378734a1) is
I have a MVVM application that contains multiple views with some complex IsReadOnly rules
I have this senario. We have an application server that contains a few web
I have a C# Windows Form application that contains a menu with this event:
I have an application that contains many controls on a panel, each with its
I have an application that contains a VC++ project (along with C# projects). Previously,
I have a silverlight application that contains Bing map. I want when the user
I have a web application that contains a bunch of classes in the App_Code
I have a scroll viewer in my application that contains a canvas, in which

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.