Solved

Encoding and decoding images in java

Posted on 2013-05-15
3
343 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
Comment Utility
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:stmani2005
stmani2005 earned 200 total points
Comment Utility
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
:)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mapShare challenge 13 67
java set up 1 45
eclipse compiler vs Installed JREs option 3 36
compre toata in where clue oracle 4 41
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now