从JSON web服务的Andr​​oid检索的byte [] [英] Retrieve byte[] in android from JSON webservice

查看:164
本文介绍了从JSON web服务的Andr​​oid检索的byte []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据库中的BLOB格式,我成功的店面形象。

I successful store image in database BLOB format.

数据类型在Web服务模型类图像的byte []。

DataType for image in webservices model class is byte [].

我的Web服务:

@POST
    @Consumes("application/json")
    @Produces("application/json")
    @Path("login")
    public Korisnici Login(Korisnici k) {

        Korisnici exception = new Korisnici(); 

............

的Json webservice的例子:

[
    {
        "id": 2,
        "ime": "haris",
        "mjestoGoogleMaps": null,
        "password": "1234",
        "username": "haris",
        "image": "iVBORw0KGgoAAAANSUhEUgAizDMizDMizDMizDMizDMizDMizDMizDMizDMizDMiz/JPL/AOc68RGNGkMYAAAAAElFTkSuQmCC"
    }
]

我们看到,JSON服务,使转换为字符串,字节[]被转换成字符串。

we see that the json service makes conversion to String, byte [] is converted into a string.

我试图使转换字符串中的Andr​​oid为byte [],但我没有看到一个图片。

I tried to make the conversion String to byte [] in Android, but I do not see a picture.

下面是我的code:

byte [] b = new byte[getString_Image().length()];

profilna.setImageBitmap(getImage(b));

从字节数组转换为位图

convert from byte array to bitmap

public static Bitmap getImage(byte[] image) {
        return BitmapFactory.decodeByteArray(image, 0, image.length);
}

如何解决这个问题呢?

How to resolve this problem?

推荐答案

使用这样

byte[] decodedString = Base64.decode(img, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
if (bitmap != null) {
Drawable image = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, 90, 100, true));
}

这篇关于从JSON web服务的Andr​​oid检索的byte []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆