Display image from byte array in ASP.NET MVC. Displaying images from wellknown URLs is quite straightforward. At times, however, you need to display images that are available as raw binary data. Consider, for example, that you are building a Captcha system that generates images on the fly. These images won't reside on the server as physical files. Convert Binary to Text web developer and programmer tools. World's simplest bin to text converter. Just paste binary in the form below, press Convert button, and you get plain text. Press button, get text. No ads, nonsense or garbage. Binary to Text Converter. Text to Octal Converter. Octal to Text Converter.
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
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).
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
- 3
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
- 1
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.
I want to some images in asp repeater which comes from databas image table.
HTML
C#
These are my codes, and get me error I cannot show images.HTML
C#
It works like that somewhere else, but with repeater I cannot read it with Eval
.
Is there any working way to show images?
![Convert Binary To Image Directly Convert Binary To Image Directly](https://i.ytimg.com/vi/HyIbvLWfknY/maxresdefault.jpg)
1 Answer
Can you try this?
Create a function
Then change your declaration like this