zoukankan      html  css  js  c++  java
  • 用FLEX实现屏幕快照及下载


    代码:

    public function printMap():void{
    var en:JPEGEncoder = new JPEGEncoder(100); //压缩图片,100是指质量
    var ba:ByteArray=en.encode(ImageSnapshot.captureBitmapData(this.parent.parent));//将控件转为BitmapData后再转为ByteArray
    var request:URLRequest = new URLRequest(”http://localhost:8080/servlet/upload.jsp”);
    request.method=”POST”;
    request.data=ba;
    request.contentType = “application/octet-stream”;
    navigateToURL(request,”_blank”); //因为要浏览器触发下载事件,所以就不用异步方式打开连接了
    }
    upload.jsp代码(如果把application/x-download改成image/jpeg就可以不弹出保存提示框了)
    代码:
    <%@page language="java” contentType=”application/x-download” import=”java.io.*,java.net.*” pageEncoding=”gb2312″%><%
    response.setContentType(”application/x-download”); //内容是下载
    response.setHeader(”Content-Disposition”,”attachment;filename=” + “test.jpg”);//文件名,可以进一步处理
    //读数据
    BufferedInputStream inputStream = new BufferedInputStream(request.getInputStream());
    //FileOutputStream outputStream = new FileOutputStream(new File(filePath));
    OutputStream outputStream = response.getOutputStream();
    byte [] bytes = new byte[1024];
    int v;
    //写数据
    while((v=inputStream.read(bytes))>0){
    outputStream.write(bytes,0,v);
    }
    outputStream.flush();
    outputStream.close();
    inputStream.close();
    %>

  • 相关阅读:
    linux性能测试(转)
    mysql基本操作(数据库,表,字段,记录)
    mysql数据库的简介(安装和卸载)
    mysql数据库
    枚举法
    python数据结构与算法简介
    自学心得
    python 进程线程阅读摘抄
    python并发编程多线程基础1
    python队列
  • 原文地址:https://www.cnblogs.com/appleseed/p/1292258.html
Copyright © 2011-2022 走看看