相关疑难解决方法(0)

确定文本宽度

我想找到正确的方法来计算C#中指定字体的文本宽度.我在Java中有以下方法,它似乎有效:

public static float textWidth(String text, Font font) {

    // define context used for determining glyph metrics.        
    BufferedImage bufImage = new BufferedImage(2 /* dummy */, 2 /* dummy */, BufferedImage.TYPE_4BYTE_ABGR_PRE);
    Graphics2D g2d = (Graphics2D) bufImage.createGraphics();
    FontRenderContext fontRenderContext = g2d.getFontRenderContext();

    // determine width
    Rectangle2D bounds = font.createGlyphVector(fontRenderContext, text).getLogicalBounds();
    return (float) bounds.getWidth();
}
Run Code Online (Sandbox Code Playgroud)

但是在C#中观察我的代码:

public static float TextWidth(string text, Font f)
{
    // define context used for determining glyph metrics.        
    Bitmap bitmap = new Bitmap(1, 1);
    Graphics grfx = Graphics.FromImage(bitmap);

    // determine …
Run Code Online (Sandbox Code Playgroud)

c# java

5
推荐指数
2
解决办法
9498
查看次数

将默认用户个人资料图片设置为其首字母的图像

越来越多的我看到公司设置用户的默认个人资料图片,如下面的截图所示,该截图来自Google主页...

在此输入图像描述

Google是如何实现这一目标的?PHP和C#的哪些API可用于实现此目的?

php c# user-profile web

5
推荐指数
2
解决办法
3448
查看次数

标签 统计

c# ×2

java ×1

php ×1

user-profile ×1

web ×1