导航:首页 > 编程语言 > java下载显示图片

java下载显示图片

发布时间:2023-02-26 01:38:21

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实现下载文件(包括图片)

用流就可以操作,起本质就是复制粘贴。希望对你有所帮助。供参考。

③ java图片显示一半

你看一下图片文件大小,如果图片文件变小了,说明上传的时候图片文件没有完整地被上传,这个时候需要你找一个网络好的地方重新上传。如果图片文件大小一样,把文件下载回本地,用图片工具打开看看图片是不是能完整显示,如果能完整显示,那就是用户那边的网络不够顺畅造成的,如果不能完整显示,则需要你找一个网络好的地方重新上传原图。总之,就是要想办法确定是服务器上图片本身有问题还是用户网络有问题。

④ java在应用程序显示图片

如果想用JLabel实现的话就是JLabel jl = new JLabel(new ImageIcon(/* 图片路径 */));

阅读全文

与java下载显示图片相关的资料

热点内容
app根据什么看是否注册 浏览:928
冰箱压缩机烫手老跳闸 浏览:254
php日志系统架构 浏览:453
udp获取服务器ip地址 浏览:985
能把心里的恐惧解压出来的视频 浏览:368
三丰云上传服务器流程 浏览:812
php类常亮 浏览:819
如何用纸尿裤做解压玩具 浏览:608
程序员年龄和工资 浏览:766
压缩空气的特性简介 浏览:564
广乐美app是做什么的 浏览:323
android的spinner属性 浏览:929
店家帮平台源码 浏览:973
源码编辑器绘制图形 浏览:951
长沙云服务器提供商 浏览:107
51单片机测脉冲宽度 浏览:286
文件夹弄成二维码 浏览:283
python字典循环添加 浏览:692
闲置服务器怎么收费 浏览:162
阅读app是用什么开发的 浏览:37