用FLEX实现屏幕快照及下载 flex导出excel文件


用FLEX实现屏幕快照及下载
Flex/Flash, Flex2, Flex3 GgNET 01月 31st. 2008, 2:53am
这种方式,在服务器端不会在磁盘上生成图片
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();
%>


flex 生成excel
http://code.google.com/p/as3xls/ 生成excel文件,然后用上面的方法先上传再下载

支持中文的as3xls http://download.csdn.net/source/839048


屏幕快照(输出到打印机)
var img:Image=new Image();
img.visible=false;
var bd:BitmapData=getBitmapData(UIComponent(Application.application));//此例中是当前应用的可视范围
img.source = new Bitmap(bd);
Application.application.addChild(img);//必须
var printJob:FlexPrintJob = new FlexPrintJob();
if (printJob.start()){
printJob.addObject(img);//这里可以还可以添加好多自己想打印的东西
}
Application.application.removeChild(img);//用后记得要移除
printJob.send();
本文来源于 冰山上的播客 http://xinsync.xju.edu.cn , 原文地址:http://xinsync.xju.edu.cn/index.php/archives/1312

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值