base64转换字节数组到一个图像

编程入门 行业动态 更新时间:2024-10-26 19:36:33
本文介绍了base64转换字节数组到一个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个form bean的属性与ID,递减和imageByteArray。 Struts动作会被执行并且我想要访问这些bean的属性一样的id,递减和转换时,imageByteArray并显示为图像重定向到一个JSP。我想这post,但是,这不是为我工作。

I have a form bean with attributes id, desc and imageByteArray. Struts action gets executed and it redirects to a JSP where i want to access these bean attributes like id, desc and convert the imageByteArray and display it as an image. I tried this post, but that's not working for me.

我带code。使用Base64编码的ByteArray - 在this.bean.imageByteArray指的form bean

I encode the bytearray using Base64 - where this.bean.imageByteArray refers to the form bean

this.bean.setImageByteArray(new org.apachemons.codec.binary.Base64().encode(imageInByteArr));

我想这一点,但不工作

I tried this, but not working

<img src="data:image/jpg;base64,<c:out value='${bean.imageByteArray}'/>" />

字节数组(字节[] imageByteArray)是指一个base64连接codeD JPG图片,我发现了以下img标签作为输出,显然没有得到显示,

Byte array (byte[] imageByteArray) refers a base64 encoded JPG image and I'm getting the following img tag as output and obviously nothing gets displayed,

<img src="data:image/jpg;base64,[B@2e200e">

不知道如何为base64字节数组,并显示转换为JSP的形象?

Any idea how to convert base64 byte array and display as an image in JSP?

推荐答案

你得到的仅仅是一个数组的toString输出。但是,您需要将字节数组转换为字符串。

What you get is just the toString output of an array. You need however the byte array converted to a String.

您应该创造豆的方法

public String getByteArrayString() { return new String(this.imageByteArray); }

和在你的JSP参考这一点。

and reference this in your JSP.

虽然在技术上应该定义用于进行Base64字节数组,它编码的所有字符都在标准的7位ASCII范围,这是没有必要的。

While technically you should define which encoding to use for an array of base64 bytes this is not necessary as all characters are in the standard 7bit ASCII range.

更多推荐

base64转换字节数组到一个图像

本文发布于:2023-06-04 08:37:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/493385.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   字节   图像

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!