国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開(kāi)發(fā) > 綜合 > 正文

根據(jù)客戶端輸入的文字生成圖片,再傳回給客戶端的webservice

2024-07-21 02:21:52
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
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  
11 <webservice(namespace:="http://www.aspalliance.com/chrisg/services")> _  
12 public class textgraphic  
13  
14  
15 <webmethod> public function drawtext( _  
16 text as string, _  
17 fontname as string, _  
18 fontsize as integer, _  
19 fontcolor as string, _  
20 alignment as string, _  
21 backcolor as string, _  
22 width as integer, _  
23 height as integer _  
24 ) as byte()  
25  
26 ' create output stream  
27 dim outstream as system.io.memorystream  
28 outstream = new system.io.memorystream()  
29  
30  
31 ' create a new bitmap image  
32 dim b as bitmap = new bitmap(width, height, pixelformat.format24bpprgb)  
33 dim g as graphics  
34 g = graphics.fromimage(b)  
35 dim fbrush as solidbrush  
36 fbrush = new solidbrush(colortranslator.fromhtml(fontcolor))  
37  
38 dim salign as new stringformat  
39 dim coords as pointf  
40  
41 if alignment.toupper = "left" then  
42 salign.alignment = stringalignment.near  
43 coords = new pointf(0,0)  
44 elseif alignment.toupper = "right" then  
45 salign.alignment = stringalignment.far  
46 coords = new pointf(0,0)  
47 else  
48 salign.alignment = stringalignment.center  
49 coords = new pointf(width/2,0)  
50 end if  
51  
52 ' blank the bitmap  
53 g.clear(colortranslator.fromhtml(backcolor))  
54  
55 ' antialias  
56 g.textrenderinghint = system.drawing.text.textrenderinghint.antialias  
57 g.smoothingmode = smoothingmode.antialias  
58  
59 g.drawstring(text, new font(fontname,fontsize),fbrush,coords,salign)  
60  
61  
62 ' serve the image to the client  
63 b.save(outstream, imageformat.gif)  
64  
65 return outstream.toarray()  
66  
67 ' clear up  
68 b.dispose()  
69 g.dispose()  
70  
71  
72  
73 end function  
74  
75 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()  
10 dim instream as system.io.memorystream  
11  
12 ' get image data  
13 bytes = gtext.drawtext("test2","tahoma",36, "#0000ff", "center", "#ffffff", 100,100)  
14 instream = new system.io.memorystream(bytes)  
15  
16 ' create a new image from stream  
17 b = new bitmap(instream)  
18  
19 ' set the content type  
20 response.contenttype="image/gif"  
21  
22 ' send the image to the viewer  
23 b.save(response.outputstream, b.rawformat)  
24  
25 ' tidy up  
26 b.dispose()  
27  
28 %>  
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 武定县| 韩城市| 攀枝花市| 伊宁县| 靖宇县| 漳州市| 堆龙德庆县| 乐陵市| 苗栗县| 嘉善县| 会泽县| 阿克苏市| 板桥市| 松桃| 乐亭县| 阿瓦提县| 长垣县| 满城县| 辽宁省| 兴安盟| 水富县| 土默特右旗| 阳东县| 连州市| 大邑县| 新闻| 额尔古纳市| 且末县| 东城区| 台南市| 澳门| 文成县| 河西区| 墨竹工卡县| 偏关县| 宜宾县| 锡林浩特市| 西和县| 调兵山市| 浏阳市| 海丰县|