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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:11:21+00:00 2026-05-28T11:11:21+00:00

I’m creating some images of text in code that need to reflect a CSS

  • 0

I’m creating some images of text in code that need to reflect a CSS Font as closely as possible. The CSS class looks like this:

.font
{
      letter-spacing: -0.7px;
      font-family: segoe wp,segoe ui,verdana,arial,helvetica,sans-serif;
      font-size: 1.15em;
      padding: 10px;
}

My image code looks like this:

using (var helper = new Bitmap(1, 1))
using (var gHelper = Graphics.FromImage(helper))
using (var font = new Font("Segoe WP", 1.15f, GraphicsUnit.Point))
using (var brush = new SolidBrush(Color.White))
{
    var size = gHelper.MeasureString(concept, font);

    using (var image = new Bitmap((int)size.Width + _padding, (int)size.Height + _padding))
    {
        using (var g = Graphics.FromImage(image))
        {
            g.Clear(Color.Black);
            g.DrawString(concept, font, brush, (float)_padding / 2, (float)_padding / 2);
        }

        var converter = new ImageConverter();
        var b = (byte[])converter.ConvertTo(image, typeof(byte[]));

        return File(b, _contentType);
    }
}

The images that are being produced by this code are VERY small.

The letter spacing I’m guessing will require that I make a loop and draw each letter individually, but how do I work with EMs inside of C#?

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

    In my opinion you can’t work with EMs, because they’re not fixed.
    Read this part (extracted from http://webdesign.about.com/od/typemeasurements/qt/how-big-is-an-em.htm):

    But How Big is an Em?
    According to the W3C an em: “is equal to the
    computed value of the ‘font-size’ property of the element on which it
    is used. The exception is when ’em’ occurs in the value of the
    ‘font-size’ property itself, in which case it refers to the font size
    of the parent element.” In other words, ems don’t have an absolute
    size. They take on their size values based on where they are. For most
    Web designers, this means that they are in a Web browser, so a font
    that is 1em tall is exactly the same size as the default font size for
    that browser.

    But how tall is the default size?
    There is no way to be 100% certain,
    as customers can change their default font size in their browsers, but
    since most people don’t you can assume that most browsers have a
    default font size of 16px. So most of the time 1em = 16px.

    So you can try:

    using (var font = new Font("Segoe WP", 16 * 1.15f, GraphicsUnit.Point))
    

    knowing from the very beginning that this is only an approximation!!

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am doing a simple coin flipping experiment for class that involves flipping a
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace

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.