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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:39:34+00:00 2026-05-28T02:39:34+00:00

I have a handler which sets a watermark on images. The problem is the

  • 0

I have a handler which sets a watermark on images. The problem is the quality is not so good.
Here is the code:

    byte[] imageBytes = null;

    using (Graphics G = Graphics.FromImage(ImageToWatermark))
    {
        using (ImageAttributes IA = new ImageAttributes())
        {
            ColorMatrix CM = new ColorMatrix();
            CM.Matrix33 = Opacity;
            IA.SetColorMatrix(CM);
            G.DrawImage(Watermark, new Rectangle(WatermarkPosition, Watermark.Size), 0, 0, Watermark.Width, Watermark.Height, GraphicsUnit.Pixel, IA);
        }
    }

    using (MemoryStream memoryStream = new MemoryStream())
    {
        ImageToWatermark.Save(memoryStream, GetImageFormat(context.Request.PhysicalPath));
        imageBytes = memoryStream.ToArray();
    }

How can I set the quality for the result?

  • 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-28T02:39:35+00:00Added an answer on May 28, 2026 at 2:39 am

    If your image format is a Jpeg, then you can set the output quality manually by using this sample method to save to disk:

        public void SaveJpg(string path, Bitmap img, long quality) {
            // Encoder parameter for image quality
            EncoderParameter qualityParam = new EncoderParameter(Encoder.Quality, quality);
    
            // Jpeg image codec
            ImageCodecInfo jpegCodec = this.getEncoderInfo("image/jpeg");
    
            EncoderParameters encoderParams = new EncoderParameters(1);
            encoderParams.Param[0] = qualityParam;
    
            img.Save(path, jpegCodec, encoderParams);
        }
    

    Or, in your case, use the following piece of code:

    using (MemoryStream memoryStream = new MemoryStream())
        {
            EncoderParameter qualityParam = new EncoderParameter(Encoder.Quality, 80); // edit image quality here
            ImageCodecInfo jpegCodec = this.getEncoderInfo("image/jpeg");
            EncoderParameters encoderParams = new EncoderParameters(1);
            encoderParams.Param[0] = qualityParam;
    
            ImageToWatermark.Save(memoryStream, encoderParams);
            imageBytes = memoryStream.ToArray();
        }
    

    In general, a quality of 60 to 100 should produce good enough Jpeg images for screen output.

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

Sidebar

Related Questions

I have a simple 'file download' generic handler which sets the response contenttype and
I have a problem that, I have a serializable class which sets and gets
I have thread exception handler which saves the exception stack trace and should close
I have a sharepoint event handler which I want to activate for a single
We have a requirment which requires to have an Handler that is extended from
I currently have a custom session handler class which simply builds on php's session
I have a message handler, which consumes from a JMS queue and that sends
I have a request handler running in apache/mod_php which occasionally expands beyond the maximum
I have a click handler, which has event.preventDefault. There is whole lot of logic
I have simple SSIS package in which On Error event handler I have created

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.