?
Solved

Encoding and decoding images in java

Posted on 2013-05-15
3
Medium Priority
?
368 Views
Last Modified: 2013-05-16
Hi there,

I have a code that teaches me (from the web) to encode and decode strings. I really need help to decode a string into image or image to string...any help is appreciated... htanks a lot...

----
import org.apache.commons.codec.binary.Base64;

public class Codec {
  public static void main(String[] args) {
    try {
      String clearText = "Hello world";
      String encodedText;

      // Base64
      encodedText = new String(Base64.encodeBase64(clearText.getBytes()));
      System.out.println("Encoded: " + encodedText);
      System.out.println("Decoded:"
          + new String(Base64.decodeBase64(encodedText.getBytes())));
      //    
      // output :
      //   Encoded: SGVsbG8gd29ybGQ=
      //   Decoded:Hello world      
      //
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}
   ---
0
Comment
Question by:zizi21
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 1200 total points
ID: 39167577
http://docs.oracle.com/javase/6/docs/api/java/io/DataInputStream.html#readFully(byte[]) is what you need if the image is in a file. You can get the array size with File.length()
0
 
LVL 9

Assisted Solution

by:Manikandan Thiagarajan
Manikandan Thiagarajan earned 800 total points
ID: 39167992
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39172432
:)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question