在获得JSON对象的字节数组图像Android应用程序 [英] getting image from byte array in JSON object to android app

查看:195
本文介绍了在获得JSON对象的字节数组图像Android应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的情况:

我有我的服务器上运行的基于REST的WCF服务,该服务是为了让各类有关从数据库中数据的人,并让这可以作为一个JSON对象的数据。它的伟大工程!

有维持在服务器上的文件系统中的图像的高速缓存另一个服务。当一个请求被发送到REST式服务,该服务然后请求将图像从图像服务。如果图像已经在缓存中(同样的宽度,高度和人的请求),它返回(一个字节数组)。我们必须利用这一服务来获取图像。

现在我要的是这个人的形象。在我们的数据库中,图像是一个长原始(EW)。不过,我已经解决了这一问题已经(previous段)。该图像现在是一个字节数组。我是pretty的新Android和我不知道该怎么找回的最佳途径此图像。我想我可以做的是字节数组添加到JSON对象,然后使用中的Base64德codeR把它转换成一个可绘制的图像。然而,每次我尝试,超时,并告诉我,它预计','或']'在为JSON对象的字符缓冲区的一些任意的索引。

我已经能够将数据从JSON对象的小位没有问题,但现在没有在它巨大的字节数组,该JSONObject的恨我。什么将是一个更好的方式,从我的服务得到这个形象?

解决方案
  1. Base64的EN $ C C字节数组得到一个字符串$。
  2. 添加字符串,JSON对象并发送。
  3. 当收到JSON,走出字符串。
  4. 的Base64德code就找回字节数组。
  5. 使用字节数组创建的图像。

Heres my situation:

I have a RESTful WCF service running on my server, the service is meant to get various types of data about people from a database and makes that data available as a single JSON object. It works great!

[EDIT]There is another service that maintains an image cache in the file system on the server. When a request is sent to the RESTful service, that service then requests an image from the image service. If the image is already in the cache (same width, height and person as the request), it returns that (as a byte array). We MUST use this service to retrieve images.

Now what I want is the image of that person. In our database, the image is a long raw (ew). However, I have dealt with that issue already (previous paragraph). The image is now a Byte array. I am pretty new to android and I am not sure what the best way to retrieve this image is. What I thought I could do was add the byte array to the JSON object and then use the base64 decoder to convert it into a drawable image. However, everytime I try, it times out and tells me it expected ',' or ']' at some arbitrary index of the char buffer for the JSON object.

I have been able to pull the small bits of data out of the JSON object without an issue, but now that there is a huge byte array in it, the JSONObject hates me. What would be a better way to get this image from my service?

解决方案

  1. Base64 encode the byte array to get a string.
  2. Add the string to JSON object and send it.
  3. When JSON is received, get out the string.
  4. Base64 decode it to get back the byte array.
  5. Use byte array to create Image.

这篇关于在获得JSON对象的字节数组图像Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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