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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:50:13+00:00 2026-05-30T11:50:13+00:00

I have created a handler for writing text on Image which call a function

  • 0

I have created a handler for writing text on Image which call a function written below

private bool HavException { get; set; }
private string ExceptionMessage { get; set; }
public Bitmap SourceImage { get; set; }
public Bitmap DestinationImage { get; set; }
public ImageMethods()
{
    HavException = false;
    ExceptionMessage = string.Empty;
}
public Image AddWatermarkText(Image img, string textOnImage)
{
    try
    {
        textOnImage = ConfigurationManager.AppSettings["textOnImage"];
        var opacity = Int32.Parse(ConfigurationManager.AppSettings["opicity"]);
        var red = Int32.Parse(ConfigurationManager.AppSettings["red"]);
        var green = Int32.Parse(ConfigurationManager.AppSettings["green"]);
        var blue = Int32.Parse(ConfigurationManager.AppSettings["blue"]);
        var fontSize = Int32.Parse(ConfigurationManager.AppSettings["fontSize"]);
        var fontName = ConfigurationManager.AppSettings["fontName"];

        var lobFromImage = Graphics.FromImage(img);
        var lobFont = new Font(fontName, fontSize, FontStyle.Bold);
        var lintTextHw = lobFromImage.MeasureString(textOnImage, lobFont);
        var lintTextOnImageWidth = (int)lintTextHw.Width;
        var lintTextOnImageHeight = (int)lintTextHw.Height;
        var lobSolidBrush = new SolidBrush(Color.FromArgb(opacity, Color.FromArgb(red, green, blue)));
        // lobFromImage.Clear(Color.White);
        lobFromImage.DrawImage(img, img.Height, img.Width);

        var posLeft = (img.Width - lintTextOnImageWidth) / 2;
        posLeft = posLeft > 0 ? posLeft : 5;
        var lobPoint = new Point(posLeft, (img.Height / 2) - (lintTextOnImageHeight / 2));
        //  var lobPoint = new Point(RandomNumber(0, img.Width - lintTextOnImageWidth), RandomNumber(0, img.Height - lintTextOnImageHeight));
        lobFromImage.DrawString(textOnImage, lobFont, lobSolidBrush, lobPoint);

        lobFromImage.Save();
        lobFromImage.Dispose();
        lobSolidBrush.Dispose();
        lobFont.Dispose();
    }
    catch (Exception ex)
    {
        HavException = true;
        ExceptionMessage = ex.Message;
    }
    return img;
}

Every thing is working fine but the size of image is getting increased by 2 to three times.
Is there any way that the size does not increase too much. I have jpg as original image.

Thanks

  • 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-30T11:50:14+00:00Added an answer on May 30, 2026 at 11:50 am

    Following call does not make sense and may be the culprit for inflating your image size:

    lobFromImage.DrawImage(img, img.Height, img.Width);
    

    This would draw the original image at (height, width) location – for example, if you have 200 x 100 image then above call would draw the image at (100, 200) location and possibly stretching your canvas to 300 x 300 size.

    For adding the watermark, all you need to do is to draw the text – so my guess is by removing above line may do the trick.

    Also lobFromImage.Save(); looks suspicious – it saves the graphic’s object state on stack and doesn’t have anything to do with saving the image on the disk.

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

Sidebar

Related Questions

I have created an ashx handler that returns an image to my flex app.
I have simple SSIS package in which On Error event handler I have created
I have an onclick handler for an <a> element (actually, it's a jQuery-created handler,
I am writing an Ajax application which uses a callback function to add a
I am writing a SharePoint web part which will have a simple ASP.NET form.
I have created a stored procedure in SQL Server, which runs immediately from Management
NOTE: I have now created a jQuery plugin which is my attempt of a
I have created HTTP handlers. How do I create global variables for these handlers
I have created a user control to handle adding comments to certain business entities,
We have created a WCF service hosted in a windows service that handles Authentication

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.