JSON Bitmap Data

Is it possible, or reasonable, to encode bitmap data in JSON to return to the web service?

Update: Yes, this worked better than I thought. I created a .NET compound object to combine images with image data

Public class AllThumbnails Public imgAllThumbs As String Public Positions () as Drawing.Rectangle Final Class

and access it through jQuery AJAX:

$.ajax({ type: "POST", url: "WebService.asmx/makeAllThumbnailsImage", data: "{DocumentNumber : \"" + DocumentNumber + "\"} ", contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { var adl = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d; var data = Base64.decode(adl.imgAllThumbs); $('#output').append("<p><strong>" + data.length + "</strong></p>"); $('#output').append("<p><strong><i>" + adl.positions.length + "<i></strong></p>"); }, failure: function (msg) { $('#output').text(msg); } }); 

I had to increase the value in my web.config since my image data exceeded the standard jsonSerialization buffer:

   <system.web.extensions>
     <scripting>
       <webServices>
         <jsonSerialization maxJsonLength = "262144">
         </jsonSerialization>
       </webServices>
     </scripting>
   </system.web.extensions>

Thanks guys for your help.

+2
json jquery
source share
3 answers

A bitmap is binary data. JSON should be represented as character data. Therefore, you need to convert binary data to character data and vice versa without losing information. Commonly used encoding for this Base64 . It is not clear which programming language you are targeting, so I canโ€™t give a more detailed answer, but almost all self-respecting languages โ€‹โ€‹have a built-in Base64 encoder or a third-party library that can do this. PHP, for example, base64_encode() and base64_decode() . Java Apache Commons Codec Base64 . For JavaScript, there is this example . And so on.

+8
source share

Sounds like Binary JSON .

Binary JSON, is a binary-encoded serialization of JSON-like documents. Like JSON, BSON supports embedding documents and arrays in other documents and arrays. BSON also contains extensions that allow you to represent data types that are not part of the JSON specification. For example, BSON is of type Date and of type BinData.

BSON can be compared to binary exchange formats, such as the Buffers protocol. BSON is no longer โ€œcircuit-freeโ€ than protocol buffers, which can give it an advantage in flexibility, but also a lack of space efficiency (BSON has overhead names in serialized data).

+2
source share

Perhaps you can use uri data ( http://en.wikipedia.org/wiki/Data_URI_scheme ) to decode encoded raster data ... it would be interesting to try :-)

+1
source share

All Articles