服务器上图片的存储
来源:互联网 发布:视频剪辑配音软件 编辑:程序博客网 时间:2024/05/01 03:32
1、图片再服务器上的存储形式:图片存在磁盘文件中,数据库保存图片的存储路径
String bitmapStr = request.getParameter("bitmap");String bitmapPath = null;<span style="white-space:pre"></span>//对客户端传的图片字符串进行解码<span style="white-space:pre"></span>try{
<span style="white-space:pre"></span>byte[] picture = new BASE64Decoder().decodeBuffer(bitmapStr);for(int i=0; i<picture.length; i++){<span style="white-space:pre"></span>if(picture[i] < 0){picture[i] += 256;}}//将图片存入文件中String filePath = "E:\\picture\\test\\";String pictureName = "p" + idStr +".png";File pictureFile = new File(filePath,pictureName);bitmapPath = filePath + pictureName;//数据库保存图片路径FileOutputStream fileStream = new FileOutputStream(pictureFile);fileStream.write(picture);fileStream.flush();fileStream.close();}catch(Exception e){<span style="white-space:pre"></span>e.printStackTrace();}
2、从服务器返回数据到客户端
list = pDao.findAll();//获取数据库中的数据Person2 person = null;String filePath = null;String bitmapStr = null;for(int i=0; i<list.size(); i++){person = (Person2)list.get(i);filePath = person.getPicture();File file = new File(filePath);//从数据库中保存的图片路径读取图片到ByteArrayOutputStream,再转换成字节数组FileInputStream fileStream = new FileInputStream(file);ByteArrayOutputStream baos = new ByteArrayOutputStream();int b;while((b = fileStream.read()) != -1){baos.write(b);}byte[] buffer = baos.toByteArray(); bitmapStr = Base64.encode(buffer, buffer.length);//将图片的字节数组转换成字符串,传回客户端 person.setPicture(bitmapStr);<span style="font-family: Arial, Helvetica, sans-serif;">//设置传回去的person图片字符串</span>
<span style="font-family: Arial, Helvetica, sans-serif;">}</span>
3、删除文件中的图片
String pictureStr = person.getPicture(); //获取person中图片的路径File file = new File(pictureStr);file.delete(); //直接删除路径对应的文件
0 0
- 服务器上图片的存储
- 浏览本地磁盘下图片的方式和浏览服务器上图片的方式
- html中默认指引服务器上图片
- kindeditor上图片上传的实现
- Android获取网络上图片的
- caffe上图片分类的实践
- centos6.6下nginx配置远程服务器上图片访问
- 网页上图片跳动
- 获取网络上图片
- 一个简单的下载网页上图片的程序
- 失望,csdn的blog贴不上图片!
- aix机上图片不能正常显示的问题
- JS实例:网页上图片延迟加载的JS代码
- Android 获取SDCard上图片和视频的缩略图
- Android 获取SDCard上图片和视频的缩略图
- Android获取SD卡上图片和视频的缩略图
- python打开远程网页上图片的大小和尺寸
- Android 获取SDCard上图片和视频的缩略图
- 获取MainFest中MetaData对应的key节点数据
- 2015年11月Xcode7.1(7B91b)打包发布苹果iOS应用指南
- caffe 如何训练自己的数据图片
- 在搜索领域,我是他们的老师,谷歌抄袭百度的技术
- BroadcastReceiver的工作过程
- 服务器上图片的存储
- qt的Qt::ConnectionType详细以及信号参数传递
- 【剑指offer-Java版】39二叉树的深度
- AsyncTask doInBackgroud not running
- java项目打包成exe文件
- 如何实时查看mysql当前连接数?
- Xcode真机测试could not find developer disk image解决方法
- QtPropertyBrowser2.6在Qt Creator中的编译部署
- Android 上传图片到后台的一直方式Base64的String形式