Flex Image加载Servlet图像流处理
来源:互联网 发布:画流程图软件visio 编辑:程序博客网 时间:2024/05/11 11:34
Image控件是Flex加载、显示图像的一个控件,当然其也可以加载SWF文件。Image加载图像有3种方式:
1)使用@Embed
,该种方式加图像数据直接编译到swf文件中去,加载速度最快,但是其编译后的swf文件较大;
2
)使用应用的相对路径
如tomcat下有个应用,flex-demo,假设flex客户端程序是发布到flex-demo的web目录下,若在web目录下有一个/statics/image/home.png文件,则image控件若要加载该文件只要设置其source如下即可:
Source = “statics/image/home.png”
,flex application在运行时会自动去服务器加载该文件。
3
)使用servlet
使用servlet进行图像加载需要做2个事情:servlet编写和image的source设置为该servlet的mapping url。
Servlet
编写:
只要该servlet继承httpservlet即可,要注意的就是
response需要输出图片文件流,代码如下:
package com.servlet;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* <p>Description:image加载图片Servlet</p>
* @author Marcus
* @version $Id: CaptureShowServlet.java,v 0.1 2010-9-27 上午08:19:09 Exp $
*/
public class CaptureShowServlet extends HttpServlet{
/**
* Comment for <code>serialVersionUID</code>
*/
private static final long serialVersionUID = 1L;
private String picFolder = "d:/pictures";
public void destroy()
{
super.destroy();
}
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
String fileName = request.getParameter("fileName");
String mimeType = "image/gif";
// Set content type
response.setContentType(mimeType);
// Set content size
File file = new File(picFolder + File.separator + fileName);
response.setContentLength((int)file.length());
// Open the file and output streams
FileInputStream in = new FileInputStream(file);
OutputStream out = response.getOutputStream();
// Copy the contents of the file to the output stream
byte[] buf = new byte[1024];
int count = 0;
while ((count = in.read(buf)) >= 0) {
out.write(buf, 0, count);
}
in.close();
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
//processRequest(request, response);
}
}
Image的source指定:
假设servlet的访问地址为http://localhost:8080/servlet/CaptureShowServlet,加载的图片文件名为pic01.jpg,则只要如下设置image的source即可:
Source = “http://localhost:8080/servlet/CaptureShowServlet?fileName=pic01.jpg”
- Flex Image加载Servlet图像流处理
- Flex Image加载Servlet图像流处理
- flex image加载图片
- Image 加载图像
- scikit-image 图像处理
- scikit-image 图像处理
- PhalApi-Image -- 图像处理
- Flex中取得Image图像原始大小
- 图像处理框架Core Image
- Python pillow Image图像处理
- as3.0 Flex 图像处理
- 在Flex中处理图像
- Loading an Image:加载一幅图像
- 【图像处理】Python-Image 基本的图像处理操作
- 【python图像处理】python的图像处理模块Image【原创】
- 【图像处理】Python-Image 基本的图像处理操作 【转载】
- 【图像处理】Python-Image 基本的图像处理操作
- Python-Image 基本的图像处理操作
- 关于单例模式和多线程之间无法实现的问题
- 学习笔记:memory location
- MySQL自增Id
- 二叉树链式结构实现
- Windows下对postgre开启远程连接权限
- Flex Image加载Servlet图像流处理
- rsync+inotify实现服务器之间文件实时同步
- js中Math.floor和Math.ceil解释以及字符串转化为数字的方法
- ant 手动打包报错: com.sun.tools.javac.Main is not on the classpPerhaps JAVA_HOME does not point to the JDK
- Android获取屏幕状态
- 如何解决"应用程序无法启动,因为应用程序的并行配置不正确"问题
- iOS开发ASIHttpRequest创建和执行request
- matlab 中eps的用法
- JAVA File Lock