㈠ java web網頁上顯示圖片
圖片不要中文名字;
圖片格式最好為.jpg,不過有的需要.png、.gif格式的圖片,有的是需要Flash支持的;
圖片的顯示也需要通過不同的瀏覽器測試,當然,如果編程,google和IE肯定是最優先測試的;
路徑不要有中文名稱,其實在項目中,圖片一般會放在一個單獨的叫image的文件夾下,這是一種習慣,我們直接寫上相對路徑,如果可以顯示一張圖片並且存在的話,那麼別的幾乎不會出錯;
調試過程,是腳本錯了,還是頁面的標簽錯誤,亦或是你的頁面代碼不規范,出現亂碼等眾多情況。
5個應該夠了~~ 你找找看是哪裡吧~~ 不會繼續問哦~
這樣可以么?
㈡ 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對話框上顯示圖片
其實有很多種方法可以解決圖片顯示大小的問題:
使用photoshop修改. 優點是可以節省系統資源, 顯示圖片的時候,不用做處理,缺點是需要了解ps的基本操作
使用JDialog 自定義對話框. 優點 可以實現復雜的效果, 缺點,代碼量比較多
使用ImageIcon, Image 類 實現圖片的縮放,. 優點: 純java代碼解決, 缺點: 如果大量的圖片需要縮放, 那麼可能影響程序的速度.
方案3的代碼如下
importjava.awt.Image;
importjavax.swing.ImageIcon;
importjavax.swing.JOptionPane;
publicclassTest{
publicstaticvoidmain(String[]args){
ImageIconicon=newImageIcon("imgs/1.png");//得到icon對象.注意我的圖片地址和你的不一樣,注意修改!!
Imageimage=icon.getImage();//icon--->Image
floatscale=0.5f;//縮放比例50%
intwidth=Math.round(icon.getIconWidth()*scale);//變小50%的寬
intheight=Math.round(icon.getIconHeight()*scale);//變小50%的高
ImageminiIcon=image.getScaledInstance(width,height,Image.SCALE_SMOOTH);
//image變成指定大小.縮放模式為SCALE_SMOOTH(平滑優先)
ImageIconsmallIcon=newImageIcon(miniIcon);//Image--->icon
JOptionPane.showInputDialog(null,"吃了嗎?","標題",0,smallIcon,null,"默認值");
}
}
效果圖
圖1 圖片顯示比例為原圖的50%
㈣ 在窗體中,java顯示圖片怎麼做
下面是一個JAVA顯示圖片的例子,請參考:
package com.tarena.java;
import t.Image;
import .File;
import .IOException;
import ageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
/**
* 載入顯示圖象,需要JDK1.5或以上
*/
public class showtu extends JFrame {
public showtu(String bmpFile) {
Image image = null;
try {
image = ad(new File(bmpFile));
} catch (IOException ex) {
}
JLabel label = new JLabel(new ImageIcon(image));
add(label);
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
}
public static void main(String[] args){
final String fileName = "F:\\456備用\\亮個相.JPG"; //換成你要顯示的圖片
vokeLater(new Runnable(){
public void run(){
new showtu(fileName).setVisible(true);
}
});
}
}
㈤ java web項目頁面中圖片顯示問題
圖片不要中文名字;
圖片格式最好為.jpg,不過有的需要.png、.gif格式的圖片,有的是需要Flash支持的;
圖片的顯示也需要通過不同的瀏覽器測試,當然,如果編程,google和IE肯定是最優先測試的;
路徑不要有中文名稱,其實在項目中,圖片一般會放在一個單獨的叫image的文件夾下,這是一種習慣,我們直接寫上相對路徑,如果可以顯示一張圖片並且存在的話,那麼別的幾乎不會出錯;
調試過程,是腳本錯了,還是頁面的標簽錯誤,亦或是你的頁面代碼不規范,出現亂碼等眾多情況。
5個應該夠了~~ 你找找看是哪裡吧~~ 不會繼續問哦~
㈥ java顯示網頁圖片
應該是環境變數沒配置好吧
㈦ java在應用程序顯示圖片
如果想用JLabel實現的話就是JLabel jl = new JLabel(new ImageIcon(/* 圖片路徑 */));
㈧ java中怎樣在界面中顯示圖片
在頁面上面顯示圖片?
<imgsrc="圖片路徑"/>
㈨ Java圖片顯示不出來,怎麼解決
你把image=new ImageIcon("海洋.png");這一語句放到label=new JLabel(image);前面,public JPanelDemo()函數裡面
再把image=new ImageIcon("海洋.png");改成image=new ImageIcon("src/海洋.png");因為你把圖片放在了src文件夾裡面
改完上述問題,你的圖片就應該能顯示出來了.
㈩ java程序產生的實時圖像如何在jsp頁面顯示
java程序產生的圖表可以用jfreechart來展示。
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html;charset=GBK");
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
LinkDataBase linker=new LinkDataBase();
String sql="select sname,courseName,marks from course,marks,student where student.rollno=marks.rollno and marks.courseid=course.courseid ";
ResultSet rs=linker.executeQuery(sql);
try
{
while(rs.next())
{
dataset.addValue(Integer.parseInt(rs.getString("marks")),rs.getString("courseName"), rs.getString("sname"));
}
}
catch(Exception e)
{
e.printStackTrace();
}
JFreeChart chart = ChartFactory.createBarChart3D(
"學生成績柱狀圖", "學生姓名", "成績", dataset, PlotOrientation.VERTICAL, true, false, false);
try {
ChartUtilities.writeChartAsJPEG(response.getOutputStream(), 1.0f, chart, 400, 300, null);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
} finally {
linker.close();
}
}
jsp頁面只需要執行這個servlet即可完成。
<body>
<img src="JFreeChartServlet" /> <br>
</body>
執行結果如下: