




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Css:.ui-widget-content background: none; /覆盖掉jqGrid自带的背景图片.alpha1background-image:url(/servlet/FileImageCreatorServlet);/此处用的是servlet生成的图片,可以自定义显示内容,也可以自己指定图片,那下面的servlet FileImageCreatorServlet.java就不需要添加了,相对对应的Web.xml也不需要配置了。width:100%; /宽度要设定,否则ie8,ie7会出现透明度失效 filter:alpha(opacity=20); /外层透明度20.alpha2 filter:alpha(opacity=100);/表格背景透明度100.Jsp: /jqGrid表格渲染table,xxxx是jqGrid表格的ID,Ps:还有关于jqgrid 表格一下特殊需求的,可以联系笔者,共同学习。QQ:695004175-如果想自定义图片内容的话,进行以下操作。-Web.xmlWeb.xml中配置生成img的servlet FileImageCreatorServlet com.linkage.bi.powershow.util.FileImageCreatorServlet FileImageCreatorServlet /servlet/FileImageCreatorServlet .java添加servlet FileImageCreatorServlet.java import java.awt.Color;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.image.BufferedImage;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.util.Date;import java.util.Properties;import java.util.Random;import javax.imageio.ImageIO;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.linkage.bi.portal.bean.StaffSessBean;import com.linkage.bi.util.DateUtil;import com.linkage.bi.util.SessionInfoUtil;public class FileImageCreatorServlet extends HttpServletprivate String fileName; private static Random rnd = new Random(new Date().getTime();/ 图片宽度private int width = 400;/ 图片高度private int height = 200;/ 外框颜色private Color rectColor = new Color(255, 255, 255);/ 背景色private Color bgColor = new Color(255, 255, 255);/ 干扰线数目private int lineNum = 0;/ 图片格式private String formatName = JPEG;/ 字体颜色private Color fontColor = new Color(0, 0, 0);/ 字体大小private int fontSize = 15;/ 文字旋转的弧度数private double radian = 0;private double rotateX = 0;private double rotateY = 0;/ 缩放private double scale = 1;public static String CONTEXT_PATH = ;/* * 随机获取颜色对象 */private Color getRandomColor(int base, int range)if (base + range) 255)range = 255 - base;int red = base + rnd.nextInt(range);int green = base + rnd.nextInt(range);int blue = base + rnd.nextInt(range);return new Color(red, green, blue);/* * 画干扰线 */private void drawRandomLine(Graphics graph)for (int i = 0; i lineNum; i+)/ 线条的颜色graph.setColor(getRandomColor(100, 155);/ 线条两端坐标值int x1 = rnd.nextInt(width);int y1 = rnd.nextInt(height);int x2 = rnd.nextInt(width);int y2 = rnd.nextInt(height);/ 画线条graph.drawLine(x1, y1, x2, y2);/* * Constructor of the object. */public FileImageCreatorServlet()super();/* * Destruction of the servlet. */public void destroy()super.destroy(); / Just puts destroy string in log/ Put your code here/* * The doGet method of the servlet. * * This method is called when a form has its tag value method equals to get. * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOExceptionprocess(request, response);/* * The doPost method of the servlet. * * This method is called when a form has its tag value method equals to * post. * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOExceptionprocess(request, response);protected void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOExceptionBufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);/设置外框颜色 若不设置 则默认白色if (rectColor = null)rectColor = new Color(255, 255, 255);/设置背景颜色 若不设置 则默认黑色if (bgColor = null)bgColor = new Color(0, 0, 0);/ 获取画布Graphics2D g = (Graphics2D)image.getGraphics();/ 画长方形g.setColor(bgColor);g.fillRect(0, 0, width, height);/ 外框g.setColor(rectColor);g.drawRect(0, 0, width - 1, height - 1);/ 画干扰线drawRandomLine(g);String text = getDrawText(request);/ 设置个性化属性this.setWidth(425); / 图片宽度this.setHeight(200); / 图片高度this.setFontColor(new Color(213, 106, 0);/ this.setLineNum(120); /干扰线条数 可以作为验证码图片this.setFontSize(20); / 字体大小this.setBgColor(new Color(255, 255, 255); / 文字旋转this.setRadian(10.0); / 旋转弧度this.setRotateX(this.getWidth() / 5);this.setRotateY(this.getHeight() * 5 / 10);/ 画字符串draw(this, g, text);/ 执行g.dispose();/ 输出图片结果 以文件流的方式输入 若想写入文件目录 第三个参数为文件目录路径ImageIO.write(image, getFormatName(), response.getOutputStream();public String getDrawText(HttpServletRequest request)/根据session信息获得 当前登录员工的名称与工号信息StaffSessBean staffSessBean = SessionInfoUtil.getStaffSessBean(request.getSession();String staffId = staffSessBean.getStaffId();/当前登录员工IDString phoneNum = staffSessBean.getMobilePhone(); /当前登录员工手机号码String now = DateUtil.getInstance().getToday(yyyy-MM-dd HH:mm:ss); /获得当前访问时间StringBuffer text = new StringBuffer();text.append( ID: ).append(staffId).append(n);if(phoneNum = null)text.append( PHONE: ).append().append(n);elsetext.append( PHONE: ).append(phoneNum).append(n);text.append(VISITTIME: ).append(now).append(n);text.append( SYSTEM: ).append(InitParamUtil.BISYS);return text.toString();/* * 在绘画板上绘制字符串 * param creator 图片创建器对象 * param g 绘画板 * param text 待绘制的字符串 */public void draw(FileImageCreatorServlet creator, Graphics2D g, String text)/ 文字旋转g.rotate(Math.toRadians(creator.getRadian(), creator.getRotateX(), creator.getRotateY();g.scale(creator.getScale(), creator.getScale();g.setColor(creator.getFontColor();Font font = new Font(,Font.PLAIN, creator.getFontSize(); /设置字体的样式 ,大小,是否为粗体等等g.setFont(font);FontMetrics fm = g.getFontMetrics(font);int fontHeight = fm.getHeight(); / 字符的高度int offsetLeft = 0;int rowIndex = 1;for (int i = 0; i = (creator.getWidth() - charWidth)rowIndex+;offsetLeft = 0;g.drawString(String.valueOf(c), offsetLeft, rowIndex * fontHeight);offsetLeft += charWidth;/* * Initialization of the servlet. * * throws ServletException if an error occurs */public void init() throws ServletException/ Put your code herepublic String getFileName()return fileName;public void setFileName(String fileName)this.fileName = fileName;public static Random getRnd()return rnd;public static void setRnd(Random rnd)FileImageCreatorServlet.rnd = rnd;public int getWidth()return width;public void setWidth(int width)this.width = width;public int getHeight()return height;public void setHeight(int height)this.height = height;public Color getRectColor()return rectColor;public void setRectColor(Color rectColor)this.rectColor = rectColor;public Color getBgColor()return bgColor;public void setBgColor(Color bgColor)this.bgColor = bgColor;public int getLineNum()return lineNum;public void setLin
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年现代汉语下册考试试题及答案
- 2025年韩语语法试题及答案
- 2025年县域旅游开发与管理专业人才招聘面试题集锦及解析
- 2025年乡村康养运营师职业技能要求与模拟题解析
- 2025年市场营销实战模拟题集与案例分析指南
- 2025年人力资源招聘面试官手册面试预测题与评估技巧解析
- 2025年初级网络推广师实战技能测试题
- 2025年公务员考试申论热点解析与范文
- 2025年全球金融投资风险管理师专业认证题库
- 2025年中国社交媒体推广专家认证考试预测题与案例分析
- 浪浪山小妖怪-2025~2026学年美术开学第一课《浪浪山小妖怪》
- 2025广东湛江市廉江市政协办公室等7个单位招聘政府雇员9人笔试参考题库附答案解析
- 2025年度制造业员工劳动合同范本
- 2025四川南充营山县医疗卫生辅助岗招募39人考试参考题库附答案解析
- 中国象棋教学课件
- 部编人教版三年级道德与法治上册全册课件
- 唱出好心情课件
- 高三开学教师大会PPT
- 媒体发稿推广合作协议模版
- 汽车底盘构造与维修课件(全)全书教学教程完整版电子教案最全幻灯片
- 电气设备运行与维护ppt课件(完整版)
评论
0/150
提交评论