ASP.NET Write Text to Image |
ASP.NET Write Text to Image ตัวอย่างการสร้างรูปภาพ และ การเขียนข้อความลงในรูปภาพ
Language Code : VB.NET || C#
Framework : 1,2,3,4
AspNetWriteTextImages1.aspx
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim intWidth,intHeight As Integer
Dim FileName As String
intWidth = 400
intHeight = 200
FileName = "MyImages/Images.png"
Dim objBitmap As Bitmap = New Bitmap(intWidth, intHeight)
Dim objGraphic As Graphics = Graphics.FromImage(objBitmap)
'*** Create Images ***'
objGraphic.FillRectangle(Brushes.Maroon, 0, 0, intWidth, intHeight)
'*** Write Text ***'
Dim strText As String = "ยินดีต้อนรับ Welcome To www.ThaiCreate.Com" '*** String ***'
Dim objFont As New Font("Tahoma", 10,FontStyle.Italic) '*** Font Style ***'
Dim objPoint As New PointF(5, intHeight - 20) '*** Point ***'
Dim objBrushWrite As New SolidBrush(Color.YellowGreen) '*** Font Color ***'
objGraphic.DrawString(strText, objFont, objBrushWrite, objPoint)
'*** Save As ***'
objBitmap.Save(Server.MapPath(FileName), ImageFormat.png)
'*** Close ***'
objGraphic.Dispose()
'*** Nothing ***'
objBitmap = Nothing
objGraphic = Nothing
'*** View Images ***'
Me.imgPicture.ImageURL = FileName
End Sub
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - Images (System.Drawing)</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Image id="imgPicture" runat="server" />
</form>
</body>
</html>
</form>
จากตัวอย่างจะเห็นว่าสามารถเขียนข้อความได้ทั้งภาษาไทย และ ภาษาอังกฤษ
Screenshot
Property & Method (Others Related) |
|