<%@ page contentType="text/html; charset=gb2312"%> 根据客户端输入的文字生成图片,再传回给客户端的webservice
网站公告:   ◆北天JAVA技术网热情为java爱好者服务,本网内容包括JAVA(JSP、servlet、EJB、webservice、j2ee、javabean、应用服务器、JavaScript),数据库(MYSQL、SQL Server、Sybase、Oracle、DB2、数据库综合知识),设计研究(设计模式、Struts、Spring、Hibernate、设计框架、设计综合知识),WEB2.0新技术(主要介绍AJAX),以及各种技术的入门、实例、例子等等,欢迎各位多来坐坐!◆  诚邀各位JAVA爱好者加盟!◆  本网站内容丰富,更新快,保证每周20篇以上!  
加入收藏
设为首页
联系站长
承接项目
  相关资源:网站首页 | 免费培训学院 | 技术论坛 | JAVA聊天室 | 作家专栏 | 开发工具 | 认证考试 | 会员俱乐部
  JAVA技术初学者园地 | jsp与servlet | javascript | Java源代码 | EJB | web service | 应用服务器 | JAVA综合知识
  设计研究设计模式 | 设计框架 | Struts | Spring | Hibernate | 开源项目 | 面向对象设计 | 设计综合知识
  数 据 库MYSQL | SQL Server | Sybase | Oracle | DB2 | Informix | Access | 数据库综合知识
  其他资源:AJAX新技术 | 网站开发 | ERP软件 | OA办公软件 | 商业智能BI | 开发综合知识 | 承接项目 | 项目试用

 
 
根据客户端输入的文字生成图片,再传回给客户端的webservice
     发布者: 发布时间:2006-06-16

   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 %>  

(转载文章请保留出处:北天JAVA技术网(www.java114.com))
 
更多精彩文章:
创建一个Windows Service应用程序
利用WebService技术实现远程数据库存取
发布一个webservice供大家使用
典型的Web Service结构
一步一步开始Web Service
Web Services犹如1995年的Java
 
        
标 题:   
内 容:   
 
                                  
 
免责声明:该文章由网友发表,如果对您造成侵权,请联系站长

首页 - 承接项目 - 网站地图 - 联系我们 -
版权所有北天JAVA技术工作室 ICP证号:粤ICP备06079815号