BBS multi-variable personalized map, generate pictures with ASP.NET web page

zhaozj2021-02-16  43

Author: Alai (Email: A at Lai.com.cn home page: http: //www.9499.net Blog: http://blog.9cbs.net/laily/)

Keywords: ASP.NET map Program VB.NET programming

Summary: Use ASP.NET to dynamically generate dynamic pictures for BBS map. That is, the ASPX page via the output of different pictures of different images by changing the querryString parameter.

On a certain day, I saw that someone used someone in the forum. I used a funny picture. The words of the speech were in the picture. I saw the address of the picture originally dynamically generated. You can generate additional pictures by rewriting some parameters in the address. , Display different text. Such an address:

http://gzx.zcat.net/isay.ashx?fontsize=24&index=02&what=helloworld

The following picture will be displayed:

Now you tried to modify the value of Fontsize, INDEX, WHAT to see, this picture is used in the forum, it is very funny :)

How does this dynamically generated image of the image implement? After some study, I found that the powerful drawing function provided by .NET is really a piece of a piece of cake.

STEP:

Built an ASP.NET web project, put some templates (if you are so lazy, don't want to do it yourself, do it directly, what parameters are empty, INDEX is equal to 1, 2 ..., generated pictures If you save it, you will check it) The file name is 1.jpg, 2.jpg, 3.jpg ..., there is a template directory.

Built a web form, don't have to add any stuff on the page, you will get the following code in the page_onload event.

Dim Size, Index, sColor, sFont, say As String Request.ContentEncoding = System.Text.Encoding.Unicode Size = Request.QueryString ( "Size") Index = Request.QueryString ( "index") sColor = Request.QueryString ( " ") SFONT = Request.QueryString (" font ") SAY = Request.QueryString (" Say ") response.clear () response.contenttype =" image / jpeg "response.charset =" GB-2312 "if Say =" "THEN SIZE = 8 index = 999 SAY =" Address after adding parameters:? Index = & say = & font = & color = & size = "SAY & =" Index: 1-9 SAY: Show text font: Font Color: Color (such as : red) Size: "end if if size =" "or not microsoft.visualbasic.isnumeric (size) THEN SIZE = 12 if index =" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" " Sfont, Single.Parse (Size)) Catch Ofont = New Font (FontFamily.Genericserif, 12) End Try Dim Strfilepath As String = Server.MAppath ("Template" & indee X & ".jpg") if not o.file.exists (strfilepath) THEN INDEX = "1" strfilepath = server.mappath ("Template" & index & ".jpg") end if Dim Obmp as bitmap if =.file .Exists (strfilepath) Then Obmp = new bitmap (strfilepath) else obmprg = new bitmap (200, 100, pixelformat.format24bpprgb) End if Dim Fcolor, Defcolor as brush defcolor =

Brushes.black Dim x as single = 10 DIM Y as single = 10 DIM W AS SINGLE = 50 DIM H AS SINGLE = 50 Select Case Index Case "1" defcolor = brushes.white W = 280: h = 70 case "2" Defcolor = brushes.red x = 0: y = 0 w = 175: h = 80 case "3" defcolor = brushes.blue x = 15: y = 310 W = 530: h = 115 case "4" defcolor = brushes. Black x = 155: y = 5 w = 435: h = 140 case "5" defcolor = brushes.red x = 5: y = 140 w = 305: h = 90 case "6" defcolor = brushes.beige x = 155 : y = 5 w = 435: h = 140 case "7" defcolor = brushes.gray x = 0: y = 0 w = 175: h = 80 case "8" Defcolor = brushes.black x = 155: y = 5 w = 435: h = 140 case "9" defcolor = brushes.darkBlue x = 155: y = 5 w = 435: h = 140 End Select SELECT CASE LCASE (Scolor) Case "White": fcolor = brushes.white case "black": fcolor = brushes.black case "red": fcolor = brushes.red case "Yellow"

: fcolor = brushes.yellow case "green": fcolor = brushes.green case "gray": fcolor = brushes.gray case "blue": fcolor = brushes.blue case "brown": fcolor = brushes.brown case "Coral" : fColor = Brushes.Coral Case "darkblue": fColor = Brushes.DarkBlue Case "gold": fColor = Brushes.Gold Case "orange": fColor = Brushes.Orange Case Else: fColor = defColor End Select Dim oGrap As Graphics = Graphics .FromImage (oBmp) oGrap.DrawString (say, oFont, fColor, New RectangleF (x, y, w, h), StringFormat.GenericTypographic) oBmp.Save (Response.OutputStream, ImageFormat.Jpeg) oGrap.Dispose () oBmp. Dispose () response.end () use method is similar to the previous, add two parameters, add font and color, usage is: Program page address? INDEX = & sign = & font = & color = & size = "

Note x, y, w, h are the position and size of the picture text box, follow the appropriate settings according to the corresponding picture. In fact, the better way is to put the relevant parameters of this picture in Web.config, will make the program more flexible and easy to deploy.

转载请注明原文地址:https://www.9cbs.com/read-20701.html

New Post(0)