Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 在VB.NET中以编程方式在文本上创建带阴影的图像_Asp.net_Vb.net_.net 4.0_Image Manipulation - Fatal编程技术网

Asp.net 在VB.NET中以编程方式在文本上创建带阴影的图像

Asp.net 在VB.NET中以编程方式在文本上创建带阴影的图像,asp.net,vb.net,.net-4.0,image-manipulation,Asp.net,Vb.net,.net 4.0,Image Manipulation,我目前正在为一个我目前正在进行的项目构建一个内部网引擎,我希望通过尽可能从代码生成标题图像来为自己节省一点时间,但是,我希望它与我们的概念图像相匹配 我希望实现以下目标: 我的问题是我根本不知道如何从代码中创建它。我能做到最基本的,但仅此而已 当涉及到渐变背景和文本上的阴影时,我开始下降。我可以在较大的标题图像上定位文本,因此如果不可能生成我在那里的精确渐变,那么我有一个解决方法,但我真正想要实现的是带有字体和阴影的文本 我想说,可以安全地假设,要使用“非标准”字体,我只需要将其安装在web服

我目前正在为一个我目前正在进行的项目构建一个内部网引擎,我希望通过尽可能从代码生成标题图像来为自己节省一点时间,但是,我希望它与我们的概念图像相匹配

我希望实现以下目标:

我的问题是我根本不知道如何从代码中创建它。我能做到最基本的,但仅此而已

当涉及到渐变背景和文本上的阴影时,我开始下降。我可以在较大的标题图像上定位文本,因此如果不可能生成我在那里的精确渐变,那么我有一个解决方法,但我真正想要实现的是带有字体和阴影的文本

我想说,可以安全地假设,要使用“非标准”字体,我只需要将其安装在web服务器上


提前感谢您的帮助。

以下是执行此任务的代码,但它是针对WinForms的。将其应用于web服务器应该不难:

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.windows.Forms

Public Class Form1

    Sub Form1_Paint(ByVal sender As Object, _
                    ByVal e As PaintEventArgs) Handles MyBase.Paint

        'g is the graphics context used to do the drawing.'
        'gp is the path used to draw the circular gradient background'
        'f is a generic font for drawing'

        Using g = e.Graphics, gp As New GraphicsPath(), _
              f As New Font(FontFamily.GenericSansSerif, 20, FontStyle.Bold)

            'add the ellipse which will be used for the '
            'circular gradient to the graphics path '
            gp.AddEllipse(Me.ClientRectangle)

            'then create a path gradient brush from the graphics path '
            'created earlier to do the drawing on the background      '

            Using pgb As New PathGradientBrush(gp)
                'set the center colour '
                pgb.CenterColor = Color.White
                'and then make all the colours around it a different colour '
                pgb.SurroundColors = New Color() {Color.LightSteelBlue}

                'fill a rectangle with the border colour of the gradient brush'
                g.FillRectangle(Brushes.LightSteelBlue, Me.ClientRectangle)
                'and then draw the gradient on top'
                g.FillRectangle(pgb, Me.ClientRectangle)

                'The secret to shadowed text is that the shadow is drawn first'
                'and it is usually offset to the lower right of the main text '
                'so we draw the shadow with a shade of grey                   '
                g.DrawString("SOME TEXT", f, Brushes.Gray, 12, 12)
                'after which we draw the text itself'
                g.DrawString("SOME TEXT", f, Brushes.Black, 10, 10)
            End Using
        End Using
    End Sub
End Class
上面的代码直接绘制到表单上。 如果要改为绘制图像,请修改代码,如下所示:

Function GetImage(....) As Image
    Dim bmp As New Bitmap(200,200) 'you may use any size here'
    Dim bmpRect As New Rectangle(Point.Empty, bmp.Size)

    Using g = Graphics.FromImage(bmp), ...
        .....
    End Using

    return bmp
End Sub
并确保使用
bmpRect
而不是
Me.ClientSize


我希望这能起作用,因为这完全是WinForms。

以下是执行此任务的代码,但它是针对WinForms的。将其应用于web服务器应该不难:

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.windows.Forms

Public Class Form1

    Sub Form1_Paint(ByVal sender As Object, _
                    ByVal e As PaintEventArgs) Handles MyBase.Paint

        'g is the graphics context used to do the drawing.'
        'gp is the path used to draw the circular gradient background'
        'f is a generic font for drawing'

        Using g = e.Graphics, gp As New GraphicsPath(), _
              f As New Font(FontFamily.GenericSansSerif, 20, FontStyle.Bold)

            'add the ellipse which will be used for the '
            'circular gradient to the graphics path '
            gp.AddEllipse(Me.ClientRectangle)

            'then create a path gradient brush from the graphics path '
            'created earlier to do the drawing on the background      '

            Using pgb As New PathGradientBrush(gp)
                'set the center colour '
                pgb.CenterColor = Color.White
                'and then make all the colours around it a different colour '
                pgb.SurroundColors = New Color() {Color.LightSteelBlue}

                'fill a rectangle with the border colour of the gradient brush'
                g.FillRectangle(Brushes.LightSteelBlue, Me.ClientRectangle)
                'and then draw the gradient on top'
                g.FillRectangle(pgb, Me.ClientRectangle)

                'The secret to shadowed text is that the shadow is drawn first'
                'and it is usually offset to the lower right of the main text '
                'so we draw the shadow with a shade of grey                   '
                g.DrawString("SOME TEXT", f, Brushes.Gray, 12, 12)
                'after which we draw the text itself'
                g.DrawString("SOME TEXT", f, Brushes.Black, 10, 10)
            End Using
        End Using
    End Sub
End Class
上面的代码直接绘制到表单上。 如果要改为绘制图像,请修改代码,如下所示:

Function GetImage(....) As Image
    Dim bmp As New Bitmap(200,200) 'you may use any size here'
    Dim bmpRect As New Rectangle(Point.Empty, bmp.Size)

    Using g = Graphics.FromImage(bmp), ...
        .....
    End Using

    return bmp
End Sub
并确保使用
bmpRect
而不是
Me.ClientSize


我希望这能起作用,因为这完全是WinForms。

如果我决定不在图像上包含背景,我可以使文本图像透明吗?将位图声明行更改为
将bmp变暗为新位图(200200,Imaging.PixelFormat.Format32bppArgb)
并跳过背景绘图代码。如果我决定不在图像上包含背景,我是否可以使文本图像透明?将位图声明行更改为
将bmp变暗为新位图(200200,Imaging.PixelFormat.Format32bppArgb)
并跳过背景绘图代码。