Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Byte To Image in JAVA

Status
Not open for further replies.

rohansr002

Programmer
Feb 19, 2010
15
IN
I have stored images in MySql in BLOB data type and retriving them using "getBinaryStream()" funtion of InputStream. But as it is returning butes of data and i want to display the original image. I dont understant how to do it???lease Help...!!!!
 
How do you want to display the image? If its on a web page you just need to reset the response, set the response content type, and write the bytes from the inputstream to the outputstream. At least thats how I do it.

Code:
java.io.InputStream is = ...
	if (is == null) {

		out.write("File not found");
		return;
	}
	response.reset();
	response.setContentType("application/bin");
	response.setHeader("Content-Disposition", "inline;filename=\""
			+ ... + "\"");
	out.clear();
	java.io.OutputStream out2 = response.getOutputStream();
	byte[] buf = new byte[1024];
	int len;
	while ((len = is.read(buf)) > 0) {
		out2.write(buf, 0, len);
	}
	return;

-----------------------------------------
I cannot be bought. Find leasing information at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top