We are about to switch to a new forum software. Until then we have removed the registration on this forum.
It's a simple question to which I'ven't got a satisfactory answer being entry level programmer in processing. It's simple to do in Python though.. How to encode an image into base64 within processing and get the encoded string?
Any easy way to do it? Would much appreciate it.. Thanks.
Answers
Colors in Processing are an integer behind the scenes which is 32 bits. Not sure why you would need them to be stored with 64 bits
Edit: What I meant was could you explain why you need 64 bit? You could always store two colors per 64 bit I guess
I need for a purpose > for uploading an image to tumblr from Processing
I need for a purpose > for uploading an image to tumblr from Processing
Not sure about Processing, but since (IIRC) you can run Java code in a sketch I'd suggest looking up a Java solution and trying that...
Yes I'm doing that but some other libraries have some duplication problems iwth the apache it's using for encoding..
Is there a simple way I can implement some java code like this in Processing to encode in base64.
the two calls to Base64.encodeBase64 and decodeBase64 are doing the heavy lifting there. they are both part of the imported org.apache.commons.codec.binary.Base64 library. (there are a million other versions too.)
you should be able to just import that same library into your processing code, at the top, and call the methods just the same.
(asimes seems confused over what base64 encoding is. it's a way of representing binary data as strings of printable characters, typically a-z, A-Z, 0-9 and two others. it dates back to when some networks would only handle 7 bits, but is used now for things like storing favicons and small images and other binary data in text files.)
http://en.wikipedia.org/wiki/Base64
@koogs, thanks
Any good resource with easily digestible example @koogs
@koogs Since there are lot of issues like image to byte array and then conversion. I'm struggling for sometime now. Any link you may suggest, I might have tried already..
So it would help if I can get some help in coding here:
1)Converting image to byte[] data ( --trying
loadPixel()
method) 2)feeding that byte array to a base 64 string(which I suppose I can do it from above )This what I'm trying to do but not working::
`
`
Also if I try the previous java code directly in Processing(after replacing the top
package com.myjeeva.image;
and all thepublic static void
withpublic void
), I get the folllowing errors:Usage: PApplet <appletname> For additional options, see the Javadoc for PApplet Could not run the sketch (Target VM failed to initialize). Make sure that you haven't set the maximum available memory too high. For more information, read revisions.txt and Help → Troubleshooting.
to which I've checked and I my processing's memory is just 10 mb(which is default preference) ..
Java 8 (at least!) has native Base64 support: https://docs.oracle.com/javase/8/docs/api/java/util/Base64.html
I thought it was made earlier, but apparently no.
Ah, I found back an old sketch. I wasn't so wrong, Base64 is built in Java in earlier versions, but it was well hidden... :-)
I found a easy hack around.
`
`
@PhiLho I found it before and it worked but I'm not sure how to use the image here.
https://www.google.fr/search?as_sitesearch=processing.org&as_q=image+to+bytes