OAF从数据库中查找Image图片并显示

从数据库中查找 Image 图片并显示。

总体流程:创建Image项,从数据库中读取Image,创建临时Image文件,设置Image属性

1.       创建Image项,Image ID:为HeaderImage


2.       首先我们要获得存储Image数据的VO

    public void InitUserInfoQuery(String UserName){

        UserInfoVOImpl vo = getUserInfoVO1();

        vo.setWhereClauseParam(0, UserName);

        vo.executeQuery();

    }

public String initImg(String path){

UserInfoVOImpl vo = getUserInfoVO1();

Row row = vo.next();

String fullpath=null ;

if (row !=null)

{

BlobDomain blobdomain = (BlobDomain)row.getAttribute("HeaderImg");

if(blobdomain != null)

{

fullpath= createFile(path, blobdomain, (String)row.getAttribute("HeaderImgName"));

row.setAttribute("ImageSource", fullpath);

}

}

return fullpath;

}

这里获得了当前通过查询获得了当前 UserInfoVO对应行所对应的存储Image数据的属性HeaderImg的值。

3.       然后通过读出的值创建临时文件

public void fromInputToOutput(InputStream inputstream, OutputStream outputstream)

    throws IOException

    {

        byte abyte0[] = new byte[255];

        for(int i = 255; i == 255;)

        {

            i = inputstream.read(abyte0);

            if(i < 0)

            break;

            outputstream.write(abyte0, 0, i);

        }

        outputstream.close();

        inputstream.close();

    }

 

    public String createFile(String s, BlobDomain blobdomain, String s1)

    {

        File file = new File(s);

        if(!file.exists())

        file.mkdirs();

        File file1 = new File(s, s1);

        System.out.println("File  Path"+file1.getPath());

        try

        {

            fromInputToOutput(blobdomain.getBinaryStream(), new FileOutputStream(file1));

        }catch(IOException ioexception)

        {

            ioexception.printStackTrace();

        }

        System.out.println("File  "+file1.getName());

        return "./fwk/t/"+ file1.getName();

     }

4.       最后在processRequest设置相应的属性

OAImageBean aimagebean=(OAImageBean)webBean.findIndexedChildRecursive("HeaderImage");

Serializable[] params = {pageContext.getTemporaryImageLocation()};

Serializable returPath= am.invokeMethod("initImg",params);

if(oaimagebean != null)

{

oaimagebean.setAttributeValue(UIConstants.SOURCE_ATTR, returPath.toString());

            oaimagebean.setWidth(120);

            oaimagebean.setHeight(120);

            oaimagebean.setBorderWidth(1);

}

总结:

难点在于临时文件的创建,及临时路径的设置

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/13615639/viewspace-609846/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/13615639/viewspace-609846/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值