Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Encoding and decoding images in java

Posted on 2013-05-15
3
349 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 300 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 8

Assisted Solution

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

Expert Comment

by:CEHJ
ID: 39172432
:)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 104
Running JavaFX on JDeveloper 12C 1 53
How to determine if a string is a valid SHA value 7 35
going to wrong jsp page 2 33
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

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