24544

conversion of byte array into image(blob) in java [duplicate]

Question:

This question already has an answer here:

<ul><li> <a href="/questions/10849893/how-to-convert-byte-array-to-blob" dir="ltr" rel="nofollow">How to convert byte array to blob</a> <span class="question-originals-answer-count"> 1 answer </span> </li> </ul>

The code for the image conversion from byte array to image i.e blob.

try { Blob image_vis = rs1.getBlob(10); InputStream x=image_vis.getBinaryStream(); OutputStream out=new FileOutputStream(string_op); byte[] bytes = string_op.getBytes(); String s=new String(bytes); System.out.println(+s); //prints bytes for the string ImageIcon icon_cap = new ImageIcon(string_op); image_cap.setIcon(icon_cap); //prints nothing to Jlabel //image_cap.setText(s); //prints a path of a image }

I am able to get path of an image, but I am anable to convert it into image format, so that it will display on a form. please help me.

Answer1:

Try This..

try { Blob image_vis = rs1.getBlob("blobColumn"); int blobLength = (int) image_vis.length(); byte[] bytes = image_vis.getBytes(1, blobLength); image_vis.free(); final BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(bytes)); ImageIO.write(bufferedImage, "jpg", new File("ImagePath/ImageName.jpg")); }

Later you can pick up the image..

Recommend

  • converting blob image to array to display in the web page in spring mvc
  • copy images from assest to sd card on install android application
  • how to use the image file located in local drive, for printing it in jsp page or servlet page?
  • How to check if the database connection is successful or not in android?
  • How to decode the H.264 video stream received from parcelfiledescriptor
  • java - Download and then write image as servlet response
  • stuck on a java phone number word generator
  • java - Download and then write image as servlet response
  • Java Image compression [closed]
  • Is it possible to simultaneousy read from and write into a java.net.Socket?
  • Scp file with jsch gives 'unexpected filename'
  • Why I cannot cast oracle BLOB from native java Blob
  • How to send NSData over an OutputStream
  • How to add a PdfPTable to the HTML string in a document at (x,y) location using iText?
  • writing to OutputStream having capacity restriction
  • Android getAssets() method throws NullPointerException
  • Content-MD5 in Jersey's Client API
  • “no main manifest attribute” after downloading a .jar file in Java
  • FileProvider “Failed to find configured root” exception
  • how to get file name from the server request?
  • Write binary data as a response in an ASP.NET MVC web control
  • How to get a path to resources?
  • How to create table in ms word doc with rowspan and colspan using apache POI?
  • How to show a limited number of pages of PDF file in JSP using iText?
  • Problems with show dialog on Background task in windows phone 8.1
  • ASP.NET Capture and replace output in Global.asax
  • How to send image as base64 string in JSON using HTTP POST in Android?
  • getResource() to a file on runtime
  • Where does the file get saved using “File file = new file(filename)” in Android
  • File random access in J2ME
  • openssl handshake failed
  • insert a picture into database(sqlite) with java code. what should i do?
  • Getting error java.io.FileNotFoundException (log4j log file) at the time of publish project on cloud
  • In Java, how can I construct a File from a resource?
  • Can I read an iPhone beacon with Windows.Devices.Bluetooth.Advertisement.BluetoothLEManufacturerData
  • Read text file that is not in the main package in a runnable jar
  • copying resource to sdcard gives a damaged file in android
  • Spark fat jar to run multiple versions on YARN
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • Is it possible to post an object from jquery to bottle.py?