web| Client View-textgraphic.asmx
<%@ WebService language= "vb" class= "Textgraphic"%>
2
3 Imports System
4 Imports System.Web.Services
5 Imports System.IO
6 Imports System.Drawing
7 Imports System.Drawing.Imaging
8 Imports System.Drawing.Drawing2D
9
10
One <webservice (namespace:= "Http://www.aspalliance.com/chrisg/services") > _
Public Class Textgraphic
13
14
<WebMethod> Public Function DrawText (_
Text as String, _
FontName as String, _
FontSize as Integer, _
FontColor as String, _
Alignment as String, _
BackColor as String, _
Width as Integer, _
% Height as Integer _
) as Byte ()
25
' Create output stream
Dim OutStream As System.IO.MemoryStream
OutStream = New System.IO.MemoryStream ()
29
30
' Create a New bitmap image
Dim b As Bitmap = New Bitmap (width, height, pixelformat.format24bpprgb)
Dim g As Graphics
g = Graphics.fromimage (b)
Dim Fbrush As SolidBrush
Fbrush = New SolidBrush (colortranslator.fromhtml (fontcolor))
37
Dim salign As New StringFormat
Dim coords As PointF
40
If alignment. ToUpper = "Left" then
Salign.alignment = Stringalignment.near
coords = New PointF (0,0)
ElseIf alignment. ToUpper = "Right" Then
Salign.alignment = Stringalignment.far
coords = New PointF (0,0)
Or else
Salign.alignment = Stringalignment.center
coords = New PointF (width/2,0)
End If
51
Blank the bitmap
G.clear (colortranslator.fromhtml (BackColor))
54
AntiAlias '
G.textrenderinghint = System.Drawing.Text.TextRenderingHint.AntiAlias
G.smoothingmode = Smoothingmode.antialias
58
g.DrawString (text, New font (fontname,fontsize), fbrush,coords,salign)
60
61
The ' serve ' the image to the client
B.save (OutStream, Imageformat.gif)
64
Outstream.toarray return ()
66
"Clear Up"
B.dispose ()
G.dispose ()
70
71
72
The End Function
74
End Class
Testtextgraphic.aspx
<%@ Page language= "vb" debug= "True"%>
2 <%@ Import namespace= "System.Drawing"%>
3 <%@ Import namespace= "System.IO"%>
4 <%
5
6 ' initialise objects
7 Dim gtext As New textgraphic
8 Dim B As Bitmap
9 Dim bytes As Byte ()
Ten Dim instream As System.IO.MemoryStream
11
' Get image data
bytes = Gtext.drawtext ("Test2", "Tahoma", "#0000ff", "center", "#ffffff", 100,100)
instream = New System.IO.MemoryStream (bytes)
15
Create a New image from stream
b = New Bitmap (instream)
18
The ' Set ' content type
Response.contenttype= "Image/gif"
21st
Send the image to the viewer
B.save (Response.outputstream, B.rawformat)
24
' Tidy up
Num B.dispose ()
27
%>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.