[android-developers] Re: How to convert a image into Base64 string?
I actually had the exact same question. The original post, the question, was pretty specific and I'm thankful not everyone on the internet answered as you originally did or google really wouldn't have any answers would it? Thankfully, others below you gave brief non-smart-alek responses that google DID pick up, and brought me straight to them.. after having to unfortunately wade through your non-helpful responses first. So let me add.. Thanks to all.. but one. On Friday, January 28, 2011 10:56:42 AM UTC-6, Hari Edo wrote: > > > This kind of question seems more like a school homework > assignment, but in case the question is practical, here goes. > > What Base64 is: > > http://en.wikipedia.org/wiki/Base64 > > This article gives plenty of examples and details that someone > can write their own fully-tested implementation in an hour. > > But in twenty seconds of using Google, I tried the search string > of "base64 encode in java" and got tons of hits. The third link > has a fully-tested implementation (based on the same Wikipedia > example data and algorithms). > > http://www.wikihow.com/Encode-a-String-to-Base64-With-Java > > Now, it's not good form to just copy code without asking, but > since this is a How-To article published on the web, I don't > think you'll run into copyright issues if you adapt their code > into your application. There's good discussion in the article > about how the code works, and advice on learning to program. > > However, this question is even sillier than that. The > Android platform even includes a class called Base64 which > does all the encoding and decoding for you. Without > worrying about incompatibility, testing, or license issues! > > http://developer.android.com/reference/android/util/Base64.html > > That class even has an .encodeToString() method that turns > your arbitrary byte[] data into a String ready for use in > sqlite TEXT fields. > > Beyond that, I'm really not sure what the actual problem is. > > I'm not trying to be rude, but it's depressing when people > ask questions that are so quickly answered with even the > most cursory search first. > > On Jan 28, 11:40 am, saex wrote: > > Hi > > > > Can someone tell me the code to transforma image (maximum of 200KB) > > into Base64 String??? > > > > i need to know how to do it with android, because i have to add the > > functionality to upload images to a remote server in my main app > > putting them into a ROW of the database, as a string. > > > > i am searching in google and in StackOverflow but i can't find easy > > examples that i can afford. And also i find some examples but they are > > not talking about to transform into String... and i need to transform > > into string to upload by JSON to my remote server. > > > > thanks -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to convert a image into Base64 string?
This kind of question seems more like a school homework assignment, but in case the question is practical, here goes. What Base64 is: http://en.wikipedia.org/wiki/Base64 This article gives plenty of examples and details that someone can write their own fully-tested implementation in an hour. But in twenty seconds of using Google, I tried the search string of "base64 encode in java" and got tons of hits. The third link has a fully-tested implementation (based on the same Wikipedia example data and algorithms). http://www.wikihow.com/Encode-a-String-to-Base64-With-Java Now, it's not good form to just copy code without asking, but since this is a How-To article published on the web, I don't think you'll run into copyright issues if you adapt their code into your application. There's good discussion in the article about how the code works, and advice on learning to program. However, this question is even sillier than that. The Android platform even includes a class called Base64 which does all the encoding and decoding for you. Without worrying about incompatibility, testing, or license issues! http://developer.android.com/reference/android/util/Base64.html That class even has an .encodeToString() method that turns your arbitrary byte[] data into a String ready for use in sqlite TEXT fields. Beyond that, I'm really not sure what the actual problem is. I'm not trying to be rude, but it's depressing when people ask questions that are so quickly answered with even the most cursory search first. On Jan 28, 11:40 am, saex wrote: > Hi > > Can someone tell me the code to transforma image (maximum of 200KB) > into Base64 String??? > > i need to know how to do it with android, because i have to add the > functionality to upload images to a remote server in my main app > putting them into a ROW of the database, as a string. > > i am searching in google and in StackOverflow but i can't find easy > examples that i can afford. And also i find some examples but they are > not talking about to transform into String... and i need to transform > into string to upload by JSON to my remote server. > > thanks -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to convert a image into Base64 string?
Perhaps the actual question is "how to get a byte[] for a given Bitmap" or vice versa. This is, indeed, Android-specific and not as obvious as the Base64 part of your question. However, again, with a couple minutes of Google use, I found this snippet: // have Bitmap bitmap from somewhere ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.JPEG,100,bos); byte[] array = bos.toByteArray(); // now have byte[] array to use, e.g., base64 encode And then on the decompression side, // have byte[] array from somewhere, e.g., base64 decode Bitmap bitmap = BitmapFactory.decodeByteArray(array, 0, array.length); // now have Bitmap bitmap to use, e.g., to make a drawable On Jan 28, 11:40 am, saex wrote: > Hi > > Can someone tell me the code to transforma image (maximum of 200KB) > into Base64 String??? > > i need to know how to do it with android, because i have to add the > functionality to upload images to a remote server in my main app > putting them into a ROW of the database, as a string. > > i am searching in google and in StackOverflow but i can't find easy > examples that i can afford. And also i find some examples but they are > not talking about to transform into String... and i need to transform > into string to upload by JSON to my remote server. > > thanks -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to convert a image into Base64 string?
If you do need to convert a byte[] to base64 and back again, the android LVL has a utility class called Base64 which does exactly that. It is completely standalone and has no imports whatsoever, so it should work fine with any version of Android. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to convert a image into Base64 string?
thanks to all! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to convert a image into Base64 string?
thanks to all! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: How to convert a image into Base64 string?
This class (as well as Base64OutputStream) is only available starting with API level 8, which may not work for all applications. -- Kostya 28.01.2011 19:56, Hari Edo пишет: However, this question is even sillier than that. The Android platform even includes a class called Base64 which does all the encoding and decoding for you. Without worrying about incompatibility, testing, or license issues! http://developer.android.com/reference/android/util/Base64.html That class even has an .encodeToString() method that turns your arbitrary byte[] data into a String ready for use in sqlite TEXT fields. -- Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: How to convert a image into Base64 string?
First get the Bitmap of Image , copy to Byte array , get the Base 64 of the byte by using codec.jar from apache 1. ByteArrayOutputStream baos = new ByteArrayOutputStream(); 2. bm.compress(Bitmap.CompressFormat.PNG, 100, baos); //bm is the bitmap object 3. byte[] b = baos.toByteArray(); 4. Base64.encode(b) () // return char[], which can covert to String On Sun, Jan 30, 2011 at 12:51 AM, saex wrote: > thanks to all! > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en