image to text file and text file to image
posted 10 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
hi all,
Would somebody help me with the code to convert image to text file using java.. and again reconstruct the image with the text file as input.??
please help me.. I am struck..
thanks in advance
Would somebody help me with the code to convert image to text file using java.. and again reconstruct the image with the text file as input.??
please help me.. I am struck..
thanks in advance
posted 10 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
What have you tried so far?
Sounds like you want OCR (Optical Character Recognition) to convert an image to text. There are already programs for that and it would be very difficult to write in Java (or any other language for that matter).
Sounds like you want OCR (Optical Character Recognition) to convert an image to text. There are already programs for that and it would be very difficult to write in Java (or any other language for that matter).
posted 10 years ago
What reconstruct the image exactly as you received it? That sounds highly unlikely unless there are some very specific things you haven't told us about this "image".
Winston
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Sangeeth priya wrote:and again reconstruct the image with the text file as input.??
What reconstruct the image exactly as you received it? That sounds highly unlikely unless there are some very specific things you haven't told us about this "image".
Winston
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Sangeeth priya
Greenhorn
Posts: 6
posted 10 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
thanks for the reply..
I need java code to convert image into text and the text into image..
i am trying with this code.
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
public class ImageTest {
public static void main(String[] args) {
try {
byte[] imageInByte;
BufferedImage originalImage = ImageIO.read(new File(
"a1.jpg"));
// convert BufferedImage to byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(originalImage, "jpg", baos);
baos.flush();
imageInByte = baos.toByteArray();
System.out.println("The encoded image byte array ============ "+imageInByte );
baos.close();
// convert byte array back to BufferedImage
InputStream in = new ByteArrayInputStream(imageInByte);
BufferedImage bImageFromConvert = ImageIO.read(in);
ImageIO.write(bImageFromConvert, "jpg", new File(
"new-darksouls.jpg"));
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
this works properly.
but when i give the conversion of byte array back to image like this:
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
public class ImageTest2 {
public static void main(String[] args) {
try {
// convert byte array back to BufferedImage
byte[] imageInByte1 = new byte[] {'[','B','@','1','c','a','1','a','6','8'};
InputStream in = new ByteArrayInputStream(imageInByte1);
BufferedImage bImageFromConvert = ImageIO.read(in);
ImageIO.write(bImageFromConvert, "jpg", new File(
"new-darksouls12.jpg"));
}
catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
i am getting null pointer exception at the line :
ImageIO.write(bImageFromConvert, "jpg", new File(
"new-darksouls12.jpg"));
if this code is wrong please suggest me the proper one. I am a beginner in this part
thanks
I need java code to convert image into text and the text into image..
i am trying with this code.
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
public class ImageTest {
public static void main(String[] args) {
try {
byte[] imageInByte;
BufferedImage originalImage = ImageIO.read(new File(
"a1.jpg"));
// convert BufferedImage to byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(originalImage, "jpg", baos);
baos.flush();
imageInByte = baos.toByteArray();
System.out.println("The encoded image byte array ============ "+imageInByte );
baos.close();
// convert byte array back to BufferedImage
InputStream in = new ByteArrayInputStream(imageInByte);
BufferedImage bImageFromConvert = ImageIO.read(in);
ImageIO.write(bImageFromConvert, "jpg", new File(
"new-darksouls.jpg"));
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
this works properly.
but when i give the conversion of byte array back to image like this:
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
public class ImageTest2 {
public static void main(String[] args) {
try {
// convert byte array back to BufferedImage
byte[] imageInByte1 = new byte[] {'[','B','@','1','c','a','1','a','6','8'};
InputStream in = new ByteArrayInputStream(imageInByte1);
BufferedImage bImageFromConvert = ImageIO.read(in);
ImageIO.write(bImageFromConvert, "jpg", new File(
"new-darksouls12.jpg"));
}
catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
i am getting null pointer exception at the line :
ImageIO.write(bImageFromConvert, "jpg", new File(
"new-darksouls12.jpg"));
if this code is wrong please suggest me the proper one. I am a beginner in this part
thanks
posted 10 years ago
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
As Pawel mentioned, you'll probably want to use base64 to encode/decode binary data.
First off, you haven't made it clear why you want text. Why not just copy the image file as binary data?
So, assuming text is what you want, base64 will encode binary data (in your case an image) into text data. There's no need to use BufferedImage, you already have an image file (.jpg) in binary format, just read the file and encode it, it doesn't matter if the binary data represents an image or not.
First off, you haven't made it clear why you want text. Why not just copy the image file as binary data?
So, assuming text is what you want, base64 will encode binary data (in your case an image) into text data. There's no need to use BufferedImage, you already have an image file (.jpg) in binary format, just read the file and encode it, it doesn't matter if the binary data represents an image or not.
| If you were a tree, what sort of tree would you be? This tiny ad is a poop beast. The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |








