当前位置:首页 » 网页前端 » web加载图片代码
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

web加载图片代码

发布时间: 2022-04-21 03:44:06

1. web中将图片设为背景图片的代码是什么

web中将图片设为背景图片的代码如下:

<html>

<body background="a.jpg">

</body>

</html>

这样就把图片a.jpg设为背景图片了。

<body bgcolor="#CCCCCC">

这个是把背景设成灰色

2. java web 读取路径中的图片并显示的问题

直接用img标签显示啊,至于路径是相对路径,当然你本地上有那个图片资源填那个绝对路径也没问题。

3. 怎么在网页中插入图片html图片代码

在网页中插入图片html图片代码方法:

步骤:

一、html图片标签语法

<imgsrc="divcss-logo-201305.gif"width="165"height="60"/>

4. webstorm中html如何添加图片

添加图片是通过img标签添加的,跟编辑器关系不大,示例如下:
<img src="图片路径" alt="图片描述">
图片的路径可以是绝对路径,也可以是相对路径,alt的图片描述是在图片加载失败的时候用来显示的,也可以不写。

5. 怎样在WEB程序设计中插入图片呢具体一点

在<body></body>中间插入图片,代码为<img
src="images/logo.gif">
一般做刚开始做网页都有一个网页文件和一个相关的文件夹
比如你现在的abc.htm和文件夹images
abc.htm是写代码用的,images就是放图片、或者样式、脚本文件或者其它相关的文件用的
而一般调用图片都采用<img
src=images/051.gif">这样的相对路径

6. 基于myeclipse的javaweb如何添加图片背景

myeclipse开发网页添加背景图片,可以使用background这个属性,加载一张图片,协商绝对路径,代码如下:
例如:bbb.jpg在image文件夹中,我们要引用bbb.jpg图片,那么我们引用的方式是(./image/bbb.jpg)。

css 代码:

body
{
background-image:url(./image/bbb.jpg);
}

如果bbb.jpg在WebRoot目录中 那我们可以直接引用:(bbb.jpg)。
css 代码:

body
{
background-image:url(bbb.jpg);
}

7. javaweb工程如何加载图片,越详细越好

比如在doGet函数里加载web工程image文件夹里的一张图片(你现在web工程里建一个),然后通过浏览器输入相应的ULR即可,弄了个小DEMO,是一个servlet,如下:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//用浏览器查看
String path = this.getServletContext().getRealPath("/image/a.jpg");//web工程下资源的路径
String filename = path.substring(path.lastIndexOf("//")+1);

FileInputStream in = null;
OutputStream out = null;
try{
in = new FileInputStream(path);
int len = 0;a
byte buffer[] = new byte[1024];
out = response.getOutputStream();
while((len = in.read(buffer))>0)
{
out.write(buffer, 0, len);
}

}finally{
if(in != null)
{
try{
in.close();

}catch(Exception e)
{
e.printStackTrace();
}
}
}

}

8. javaweb项目图片加载问题

图片都保存在数据库里面吧,要这样写:
ServletOutputStream sout = response.getOutputStream();
// jdbc 查数据库
// selct image from imagetable where ......
sout.write(rs.getBytes(1));
sout.flush();

9. WebView怎么加载图片

将Html代码通过String的形式被加载到WebView中,而且在Html中可以引用存储在设备中的图片资源等。这个方式可以非常方便的实现 RichTextField的效果,尤其是对某些程序提供一些本地的简单文档时,非常方便。
下边是实现这个功能的源代码:
public void loadHTML() {
final String mimeType = "text/html";
final String encoding = "utf-8";
final String html = "<h1>Header</h1><p>Custom HTML</p>
<p><img src=\"file:///android_asset/image1.jpg\" />
</p>";
WebView wv = (WebView) findViewById(R.id.wv1);
wv.loadDataWithBaseURL("fake://not/needed", html,mimeType, encoding, "");
}

10. java web开发,上传图片并读取

java web开发中,使用文件操作类来上传图片并读取,如下代码:

*@desc:图片处理工具
*@author:bingye
*@createTime:2015-3-17下午04:25:32
*@version:v1.0
*/
publicclassImageUtil{

/**
*将图片写到客户端
*@author:bingye
*@createTime:2015-3-17下午04:36:04
*@history:
*@paramimage
*@paramresponsevoid
*/
publicstaticvoidwriteImage(byte[]image,HttpServletResponseresponse){
if(image==null){
return;
}
byte[]buffer=newbyte[1024];
InputStreamis=null;
OutputStreamos=null;
try{
is=newByteArrayInputStream(image);
os=response.getOutputStream();
while(is.read(buffer)!=-1){
os.write(buffer);
os.flush();
}
}catch(IOExceptione){
e.printStackTrace();
}finally{
try{
if(is!=null){is.close();}
if(os!=null){os.close();}
}catch(IOExceptione){
e.printStackTrace();
}
}
}

/**
*获取指定路劲图片
*@author:bingye
*@createTime:2015-3-21上午10:50:44
*@paramfilePath
*@paramresponsevoid
*/
publicstaticvoidwriteImage(StringfilePath,HttpServletResponseresponse){
FileimageFile=newFile(filePath);
if(imageFile!=null&&imageFile.exists()){
byte[]buffer=newbyte[1024];
InputStreamis=null;
OutputStreamos=null;
try{
is=newFileInputStream(imageFile);
os=response.getOutputStream();
while(is.read(buffer)!=-1){
os.write(buffer);
os.flush();
}
}catch(FileNotFoundExceptione){
e.printStackTrace();
}catch(IOExceptione){
e.printStackTrace();
}finally{
try{
if(is!=null){is.close();}
if(os!=null){os.close();}
}catch(IOExceptione){
e.printStackTrace();
}
}
}
}

/**
*图片上传到文件夹
*@author:bingye
*@createTime:2015-3-20下午08:07:25
*@paramfile
*@paramsavePath
*@returnboolean
*/
(CommonsMultipartFilefile,StringsavePath){
if(file!=null&&!file.isEmpty()){
//获取文件名称
StringfileName=file.getOriginalFilename();
//获取后缀名
StringsuffixName=fileName.substring(fileName.indexOf(".")+1);
//新名称
StringnewFileName=System.currentTimeMillis()+"."+suffixName;
//新文件路劲
StringfilePath=savePath+newFileName;
//获取存储文件路径
FilefileDir=newFile(savePath);
if(!fileDir.exists()){
//如果文件夹没有:新建
fileDir.mkdirs();
}
FileOutputStreamfos=null;
try{
fos=newFileOutputStream(filePath);
fos.write(file.getBytes());
fos.flush();
returnResultUtil.success("UPLOAD_SUCCESS",URLEncoder.encode(newFileName,"utf-8"));
}catch(Exceptione){
e.printStackTrace();
returnResultUtil.fail("UPLOAD_ERROR");
}finally{
try{
if(fos!=null){
fos.close();
}
}catch(IOExceptione){
e.printStackTrace();
returnResultUtil.fail("UPLOAD_ERROR");
}
}
}
returnResultUtil.fail("UPLOAD_ERROR");
}}