Flash8的位图缓冲应用:大头贴 -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【www.unjs.com - 电脑资料】

   

    个人觉得这个方法比用flashcom要便宜的多,就是有点费资源,不过要求的环境非常简单,

Flash8的位图缓冲应用:大头贴

。过两天给大家看看一个正式应用的

    http://220.194.55.60:8080/bitmap/MDT.html

    这是我用Flash8的位图缓冲制作的大头贴应用。

    完全独立于FlashCom,这个大头贴不像以前的,要FlashCommunicationServer来帮助。

    这个利用Flash8的位图缓冲技术制作,不需要FlashCommunicationServer 服务端的java程序编写真是费了我老大的劲啊!!熬了两天,不过还算值得,哈哈 注意:如果要测试,必须有一个摄像头和Flash Player 8才行。(其实,摄像头也不是必须的,没有摄像头,你就看不到真实效果,但是功能还是可以实现的,哈哈)

    http://220.194.55.60:8080/bitmap/MDT.html

    我把javaBean给放上,还有那个接受的jsp文件

    先看jsp吧

    <%@ page contentType="text/html; charset=gb2312" language="java" import="com.n0rthwood.*" errorPage="" %>

    <%

    //防止缓存

    response.setHeader("Pragma", "no-cache");

    response.setHeader("Cache-Control", "no-cache");

    //计数器

    String click=(String)application.getAttribute("click");

    %>

    <%

    //初始化计数器

    if(click==null||click.equals("")){

    click="1";

    }

    int tmp=Integer.parseInt(click);

    tmp=tmp+1;

    click=""+tmp;

    application.setAttribute("click",click);

    //接收图片长宽

    String widthStr=(String)request.getParameter("width");

    String heightStr=(String)request.getParameter("height");

    if(widthStr==null||heightStr==null||widthStr.equals("")||heightStr.equals("")){

    //转向错误页面

    response.sendRedirect("erro.jsp");

    return;

    }

    %>

    <%

    //将长宽由字符串转换为整型

    int widthInt=Integer.parseInt(widthStr);

    int heightInt=Integer.parseInt(heightStr);

    //接收图片像素,由于图片像素是以行为单位的数组,所以要循环height那么多次才能接收到所有行。

    String[] pixelColor=new String[widthInt-1];

    for(int i=0;i

    pixelColor[i]=(String)request.getParameter("px"+i);

    }

    try{

    //调用我的javaBean来写图片到硬盘

    com.n0rthwood.JpgTest.JpgTset(widthInt,heightInt,pixelColor);

    //转向那张刚生成的图片

    response.sendRedirect("temp.jpg");

    }catch(Exception e){

    //如果出错,显示错误信息

    out.println(e.toString());

    }

    %>

    然后是javaBean

    package com.n0rthwood;

    import java.io.File;

    import java.io.FileOutputStream;

    import java.awt.Graphics2D;

    import java.awt.Graphics;

    import java.awt.Image;

    import java.awt.image.BufferedImage;

    import com.sun.image.codec.jpeg.JPEGCodec;

    import com.sun.image.codec.jpeg.JPEGImageEncoder;

    public class ImageSaver{

    //静态方法:参数含义:int 宽,int 高,包含颜色信息的字符串数组,这里如果你不明白这个数组怎么回事,可以去看一下我前面一片blog里提到的那个地址,那里有关于flash文件如何写,还有传递到服务器的所有参数,

电脑资料

Flash8的位图缓冲应用:大头贴》(https://www.unjs.com)。

    public static void JpgTset(int width,int height,String[] rowColor) throws Exception{

    BufferedImage bufimg= new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);

    for(int i=0;i

    //调用下面的那个静态类把字符串转成数组

    String[] colDot=StringtoArray(rowColor[i],",");

    for(int j=0;j

    int rgb=Integer.parseInt(colDot[j],16);

    //为每个像素设置颜色

    bufimg.setRGB(j,i,rgb);

    }

    }

    //该保存了

    FileOutputStream out=new FileOutputStream("temp.jpg");

    //用jpg格式来压缩

    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);

    encoder.encode(bufimg);

    out.close();

    }

    /*这个类把字符串转换成数组:比如你有个字符串是"a,b,c,d,e,f,g"分隔符是逗号,用这个函数可以得到一个字符串数组:比如s[6], 你会发现,a就等于s[0].b就是s[1]一次类推。

    如果你不知道为什么要这么做,请参见第一篇文章中的那个连接。*/

    public static String[] StringtoArray( String s, String sep ) {

    StringBuffer buf = new StringBuffer(s);

    int arraysize = 1;

    for ( int i = 0; i < buf.length(); i++ ) {

    if ( sep.indexOf(buf.charAt(i) ) != -1 )

    arraysize++;

    }

    String [] elements = new String [arraysize];

    int y,z = 0;

    if ( buf.toString().indexOf(sep) != -1 ) {

    while ( buf.length() > 0 ) {

    if ( buf.toString().indexOf(sep) != -1 ) {

    y = buf.toString().indexOf(sep);

    if ( y != buf.toString().lastIndexOf(sep) ) {

    elements[z] = buf.toString().substring(0, y ); z++;

    buf.delete(0, y + 1);

    }

    else if ( buf.toString().lastIndexOf(sep) == y ) {

    elements[z] = buf.toString().substring(0, buf.toString().indexOf(sep));

    z++;

    buf.delete(0, buf.toString().indexOf(sep) + 1);

    elements[z] = buf.toString();z++;

    buf.delete(0, buf.length() );

    }

    }

    }

    }

    else {elements[0] = buf.toString(); }

    buf = null;

    return elements;

    }

    }

最新文章