Java如何获取网页上的图片转成Image对象
比如有一个图片的网址是http://www.minecraft-servers-list.org/plugins/MinecraftIdList/img/1-0.png,...
比如有一个图片的网址是http://www.minecraft-servers-list.org/plugins/MinecraftIdList/img/1-0.png,怎么把它获取成Image对象?
(最好能不下载,就是在线加载。不过下载也行) 展开
(最好能不下载,就是在线加载。不过下载也行) 展开
2018-08-17 · 知道合伙人互联网行家
关注
展开全部
// 这是一个嵌入到网页中动态显示50是张图片的java小应用程序,希望你对有帮助!
import java.awt.*;
import java.applet.*;
public class Picture extends Applet
{
Image[] theImages;
int nNum = 50;
int nNow = 0;
public void init()
{
theImages = new Image[nNum];
for(int i = 0; i < nNum ; i++)//将图片装入数组
theImages[i] = getImage(getDocumentBase(), "pic" + Integer.toString(i) + ".jpg");
}
public void start()
{
nNow = 0;
}
public void paint(Graphics g)
{
g.drawImage(theImages[nNow],500,500,this);
nNow++;
if(nNow>=nNum)
nNow = 0;
try
{
Thread.sleep(50);
}
catch(Exception e){showStatus(e.toString());}
repaint();
}
public void main()
{
Graphics g;
g=this.getGraphics ();
init();
start();
paint(g);
}
}
import java.awt.*;
import java.applet.*;
public class Picture extends Applet
{
Image[] theImages;
int nNum = 50;
int nNow = 0;
public void init()
{
theImages = new Image[nNum];
for(int i = 0; i < nNum ; i++)//将图片装入数组
theImages[i] = getImage(getDocumentBase(), "pic" + Integer.toString(i) + ".jpg");
}
public void start()
{
nNow = 0;
}
public void paint(Graphics g)
{
g.drawImage(theImages[nNow],500,500,this);
nNow++;
if(nNow>=nNum)
nNow = 0;
try
{
Thread.sleep(50);
}
catch(Exception e){showStatus(e.toString());}
repaint();
}
public void main()
{
Graphics g;
g=this.getGraphics ();
init();
start();
paint(g);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询