java代码中图片的类型 java支持的图片格式

java提取数据库中blob类型的图片,如何全部显示在jsp页面?在OracleQueryBean类中增加一个函数java代码中图片的类型 , 来进行读取java代码中图片的类型 , 具体代码如下java代码中图片的类型:
/**
* 根据图片在数据库中java代码中图片的类型的ID进行读取
* @param strID 图片字段ID
* @param w需要缩到的宽度
* @param h需要缩到高度
* @return
*/
public byte[] GetImgByteById(String strID, int w, int h){
//System.out.println("Get img data which id is " + nID);
if(myConnection == null)
this.getConnection();
byte[] data = https://www.04ip.com/post/null;
try {
Statement stmt = myConnection.createStatement();
ResultSet myResultSet = stmt.executeQuery("select " + this.strIDName + " from " + this.strTabName + " where " + this.strIDName + "=" + strID);
StringBuffer myStringBuffer = new StringBuffer();
if (myResultSet.next()) {
java.sql.Blob blob = myResultSet.getBlob(this.strImgName);
InputStream inStream = blob.getBinaryStream();
try {
long nLen = blob.length();
int nSize = (int) nLen;
//System.out.println("img data size is :" + nSize);
data = https://www.04ip.com/post/new byte[nSize];
inStream.read(data);
inStream.close();
} catch (IOException e) {
System.out.println("获取图片数据失败,原因:" + e.getMessage());
}
data = https://www.04ip.com/post/ChangeImgSize(data, w, h);
}
System.out.println(myStringBuffer.toString());
myConnection.commit();
myConnection.close();
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
return data;
}
页面使用OracleQueryBean来根据用户提供的图片id进行查询,在读取并进行缩放后,通过jsp页面进行展示 , 具体代码如下:
%@ page language="java" contentType="text/html;;charset=gbk" %
jsp:useBean id="OrcleQuery" scope="page" class="HLFtiDemo.OracleQueryBean" /
%
response.setContentType("image/jpeg");
//图片在数据库中的 ID
String strID = request.getParameter("id");
//要缩略或放大图片的宽度
String strWidth = request.getParameter("w");
//要缩略或放大图片的高度
String strHeight = request.getParameter("h");
byte[] data = https://www.04ip.com/post/null;
if(strID != null){
int nWith = Integer.parseInt(strWidth);
int nHeight = Integer.parseInt(strHeight);
//获取图片的byte数据
data = https://www.04ip.com/post/OrcleQuery.GetImgByteById(strID, nWith, nHeight);
ServletOutputStream op = response.getOutputStream();
op.write(data, 0, data.length);
op.close();
op = null;
response.flushBuffer();
//清除输出流,防止释放时被捕获异常
out.clear();
out = pageContext.pushBody();
}
%
从文件中读取图片和写入图片到文件里的java代码是什么?首先导入各种需要的包:
import java.awt.Image;
import javax.imageio.ImageIO;
import java.io.*;
读取图片的方法如下:
Image[] array = new Image[10];
Image image = ImageIO.read(new File("d:\\source.gif"));//根据你实际情况改文件路径吧
array[0] = image;
图片读出来了 。
如果你有一个Image对象,想把它写入文件可以这样做:
BufferedImage image = ImageIO.read(new File("d:\\source.gif"));
//要想保存这个对象的话你要把image声明为BufferedImage 类型
ImageIO.write(image, "png", new File("f:\\test.png"));
通过文字搜索图片 java代码实现及说明import ja.io.*;
//获取文件夹内容
public class getthing
{
public static void main(String[] args) throws Exception
{
System.out.println(welstr);

推荐阅读