導航:首頁 > 動漫圖片 > java中怎麼讀取圖片

java中怎麼讀取圖片

發布時間:2023-01-09 19:54:31

Ⅰ 在JAVA中如何將圖片從資料庫讀取到頁面上

這是用Struts做的
<img src="<bean:write name="item" property="page"/>" width="100" height="100">

圖片文件夾必須在伺服器里

Ⅱ java 怎樣從磁碟讀取圖片文件

用JFileChoose 這個類,用來選擇文件 主要代碼如下:
JFileChooser f = new JFileChooser(); // 查找文件
f.setFileFilter(new FileNameExtensionFilter("圖片文件(*.bmp, *.gif, *.jpg, *.jpeg, *.png)", "bmp", "gif","jpg", "jpeg", "png"));
int rVal = f.showOpenDialog(null);

Ⅲ 用java怎麼讀取圖片

思路:使用 java.awt.Image包下的Image可以接收圖片。讀取則使用ImageIO對象。

代碼如下:

/**
* 讀取圖片,首先導入以下的包
*/
import java.awt.Image;
import javax.imageio.ImageIO;
import java.io.*;

/**
* 用Image對象來接收圖片
* 路徑根據實際情況修改
*/
Image image = ImageIO.read(new File("c:\\1.png"));
System.out.println(image.getSource());

Ⅳ 請教如何用Java語言讀取jpg圖片,並顯示

1、獲取文件夾的路徑 2、得到文件夾中的有圖片的名稱,可以存到數組或者集合中 3、你再到jsp頁面做顯示, 4、下面是獲取路徑和文件名的代碼,前台顯示的代碼自己寫 String path = 文件夾路徑; String names = ""; try { File f = new File(path)

Ⅳ Java如何讀取文件夾中所有圖片,並顯示出來

說一下思路吧,首先遍歷文件夾,找到對應後綴的文件(png,jpg之類的),然後創建Bitmap對象,使用inputStream將文件轉成bitmap對象,之後使用imageview或者GLview顯示圖片即可。
注意對大圖進行壓縮,結束時圖片必須回收處理,bitmap.recycle()否則圖片多了內存溢出

Ⅵ 求助一下關於java怎麼讀取圖片路徑

圖像放錯地方了,最好是放在根目錄下面(reboot下面),搜尋時從根目錄開始的,直接把image放在這里就可以了。

Ⅶ java讀取圖片問題

import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.*;

public class Test{
public static void main(String args[]) {
int[] rgb = new int[3];

File file = new File("a.bmp");
BufferedImage bi=null;
try{
bi = ImageIO.read(file);
}catch(Exception e){
e.printStackTrace();
}

int width=bi.getWidth();
int height=bi.getHeight();
int minx=bi.getMinX();
int miny=bi.getMinY();
System.out.println("width="+width+",height="+height+".");
System.out.println("minx="+minx+",miniy="+miny+".");

for(int i=minx;i<width;i++){
for(int j=miny;j<height;j++){
//System.out.print(bi.getRGB(jw, ih));
int pixel=bi.getRGB(i, j);
rgb[0] = (pixel & 0xff0000 ) >> 16 ;
rgb[1] = (pixel & 0xff00 ) >> 8 ;
rgb[2] = (pixel & 0xff );
System.out.println("i="+i+",j="+j+":("+rgb[0]+","+rgb[1]+","+rgb[2]+")");

}
}

}

}

Ⅷ Java中怎麼抓取網頁中的圖片

通過httpclient來爬取網站內容,分析當前內容頁中的圖片『規則』
抓取一般都是模擬瀏覽器訪問目標網頁,通過返回的頁面html代碼進行分析自己需要的數據
查找規則,例如你爬取的網頁 ,看到當前頁面顯示的圖片格式如下<img src="http://www..com/img/20101025_user.png">
通過解析爬取的網頁源代碼(html)進行字元串的操作即可,現在有相應的第三方jar包可以幫你更快的完成這部分工作,例如htmlpaser,獲取到對應的地址,然後進行保存或下載。
你可以搜索,java爬蟲(httpclient)和htmlpaser做更多的了解。

Ⅸ java如何讀取文件夾中的圖片並在界面顯示

下面給你提供一個實現,該實現採用了代理模式。這個實現包含兩個文件,分別是Client.java和ImageIcoProxy.java,ImageIcoProxy.java負責了圖片的延遲載入,你可以修改為不延遲即可。

Client.java的代碼為:
import java.awt.Graphics;
import java.awt.Insets;

import javax.swing.Icon;
import javax.swing.JFrame;

public class Client extends JFrame {
private static int IMG_WIDTH = 510;
private static int IMG_HEIGHT = 317;
private Icon imgProxy = null;
public static void main(String[] args) {
Client app = new Client();
app.setVisible(true);
}

public Client() {
super("Virture Proxy Client");
imgProxy = new ImageIcoProxy("D:/test.jpg", IMG_WIDTH, IMG_HEIGHT);
this.setBounds(100, 100, IMG_WIDTH + 10, IMG_HEIGHT + 30);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint(Graphics g) {
super.paint(g);
Insets insets = getInsets();
imgProxy.paintIcon(this, g, insets.left, insets.top);
}
}

ImageIcoProxy.java的代碼為:
import java.awt.Component;
import java.awt.Graphics;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.SwingUtilities;

public class ImageIcoProxy implements Icon {

private ImageIcon realIcon = null;
private String imgName;
private int width;
private int height;
boolean isIconCreated = false;
public ImageIcoProxy(String imgName, int width, int height) {
this.imgName = imgName;
this.width = width;
this.height = height;
}

public int getIconHeight() {
return realIcon.getIconHeight();
}

public int getIconWidth() {
return realIcon.getIconWidth();
}

public void paintIcon(final Component c, Graphics g, int x, int y) {
if (isIconCreated) {
//已經載入了圖片,直接顯示
realIcon.paintIcon(c, g, x, y);
g.drawString("Just Test", x + 20, y + 370);
} else {
g.drawRect(x, y, width-1, height-1);
g.drawString("Loading photo...", x+20, y+20);
synchronized(this) {
SwingUtilities.invokeLater(new Runnable() {

public void run() {
try {
Thread.currentThread().sleep(2000);
realIcon = new ImageIcon(imgName);
isIconCreated = true;
} catch (Exception e) {
e.printStackTrace();
}
c.repaint();
}

}
);
}
}
}

}

閱讀全文

與java中怎麼讀取圖片相關的資料

熱點內容
呆萌的蜻蜓高清圖片 瀏覽:539
怎麼把圖片里的照片截下來 瀏覽:803
中年女梨花燙中長發型圖片 瀏覽:475
3dmax怎麼保存tiff圖片 瀏覽:845
怎麼刪掉微信里的圖片 瀏覽:540
男黑色馬甲搭配衣服圖片 瀏覽:194
深紫藍色頭發圖片女生 瀏覽:124
小卷中發燙發發型圖片 瀏覽:839
word怎麼讓圖片按順序放映 瀏覽:103
男穿緊身奧特曼衣服圖片 瀏覽:137
美術繪畫作品圖片簡單漂亮手抄報 瀏覽:675
一年級畫畫的圖片大全簡單的圖片 瀏覽:344
男生親女生腳圖片 瀏覽:991
可愛狗狗圖片金毛 瀏覽:950
非洲男生服裝圖片 瀏覽:913
word文檔背景怎麼改圖片 瀏覽:719
賽爾號動漫人物圖片大全圖片 瀏覽:918
包文字圖片 瀏覽:515
中華人民共和國國徽圖片高清全圖 瀏覽:876
播放卡通女孩了的圖片 瀏覽:761