jsf <aj4>中outputmedia显示图片的问题 20
1个回答
展开全部
<a4j:mediaOutput element="img" mimeType="image/jpeg"
createContent="#{fileUploadBean.paint}"
style="width:100px; height:100px;" cacheable="false">
</a4j:mediaOutput>
public void paint(OutputStream out,Object object)
{
try
{
//必须有网线
URL url = new URL("http://i1.sinaimg.cn/ty/s/2009-06-17/1245182714_oYaPWI.jpg");
URLConnection conn = url.openConnection();
Image image = ImageIO.read(conn.getInputStream());
System.out.println(image);
//InputStream is = new FileInputStream(this.fileAddress("苹果"));
//Image image = ImageIO.read(is);
int width = image.getWidth(null);
int height = image.getHeight(null);
BufferedImage bi = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
bi.getGraphics().drawImage(image, 0, 0, width, height,null,null);
ImageIO.write((RenderedImage) image, "jpg", out);
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
}
createContent="#{fileUploadBean.paint}"
style="width:100px; height:100px;" cacheable="false">
</a4j:mediaOutput>
public void paint(OutputStream out,Object object)
{
try
{
//必须有网线
URL url = new URL("http://i1.sinaimg.cn/ty/s/2009-06-17/1245182714_oYaPWI.jpg");
URLConnection conn = url.openConnection();
Image image = ImageIO.read(conn.getInputStream());
System.out.println(image);
//InputStream is = new FileInputStream(this.fileAddress("苹果"));
//Image image = ImageIO.read(is);
int width = image.getWidth(null);
int height = image.getHeight(null);
BufferedImage bi = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
bi.getGraphics().drawImage(image, 0, 0, width, height,null,null);
ImageIO.write((RenderedImage) image, "jpg", out);
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询