2019独角兽企业重金招聘Python工程师标准>>>

package com.example.gally_3d;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.util.Log;public class ShowAllPic {/*** 遍历整个sd卡,获得所有图片的路径信息的集群*/public void ListFiles(String path, List<String> listPath) {// File file = new File(path);File file = new File(path.substring(0, path.lastIndexOf("/")));if (!file.exists()) {file.mkdir();}if (file == null) {return;} else if (file.isDirectory() && path.length() > 4) {// 如果路径长度小于4,表示路径不存在(sdcard)String reName = path.substring(0, 4);// Log.i("aaa", reName+" fileName1");if (reName.equals("/sys") || reName.equals("/tmp")|| reName.equals("/pro")) {// 系统文件return;}}File[] fs = file.listFiles();if (fs == null) {FileSave(path, null);Log.i("aaa", " fileName2");return;}// Recursion(fs, listPath);for (File f : fs) {if (f == null) {continue;} else {String fileName = f.getName();
//    Log.i("aaa", fileName + " fileName");String htx = fileName.substring(fileName.lastIndexOf(".") + 1,fileName.length()).toLowerCase();// 取得扩展名,并且将值转化成小写// if (htx.equals("png") || htx.equals("gif") ||// htx.equals("jpg")// || htx.equals("bmp")) {// listPath.add(f.getPath());// Log.i("aaa", listPath.size() + " asdasdas " + f.getPath());// }
//    Log.i("aaa", htx + " asdasdas " + f.getPath());if (htx.substring(0).equals("jpg")|| htx.substring(0).equals("png")) {listPath.add(f.getPath());}path = f.getAbsolutePath();if (f.isDirectory() == true) {ListFiles(path, listPath); // 当f为文件夹的时候,进入文件夹中}}}}public static void FileSave(String filename, Bitmap bitmap) {// String fileName = "/sdcard/myImage/111.jpg";
//  Log.i("aaa", filename+" filename");String sdStatus = Environment.getExternalStorageState();if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { // 检测sd是否可用
//            Log.i("aaa",
//                    "SD card is not avaiable/writeable right now.");return;}Log.i("liang", filename.substring(0, filename.lastIndexOf("/"))+" filename");File file = new File(filename.substring(0, filename.lastIndexOf("/")));if (!file.exists()) {file.mkdirs();// 创建文件夹}else{
//   Log.i("aaa",
//            "sd");}FileOutputStream b;try {b = new FileOutputStream(filename);if (bitmap.compress(Bitmap.CompressFormat.JPEG, 100, b)) {// 把数据写入文件
//    Log.i("aaa", "sd png");}else{Log.i("aaa", "no sd png");}b.flush();b.close();} catch (FileNotFoundException e) {e.printStackTrace();Log.i("aaa", e.getMessage()+" a");} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();Log.i("aaa", e.getMessage()+" b");}}/** 取得网络上的图片 * @param  context */public static Bitmap GetNetBitmap(String url) {URL imageUrl = null;Bitmap bitmap = null;try {imageUrl = new URL(url);} catch (MalformedURLException e) {Log.v("aaa", e.getMessage());}if (imageUrl != null) {try {HttpURLConnection conn = (HttpURLConnection) imageUrl.openConnection();conn.setDoInput(true);// 设置请求的方式conn.connect();InputStream is = conn.getInputStream();// 将得到的数据转化为inputStreambitmap = BitmapFactory.decodeStream(is);// 将inputstream转化为Bitmapis.close();// 关闭数据String fileName=url.substring(url.lastIndexOf('/')+1,url.length());FileSave("/sdcard/Gallery3D/"+fileName, bitmap);} catch (IOException e) {e.printStackTrace();}} else {Log.v("aaa", "Url is Null!!");}return bitmap;}//File file = new File(path);
// file.delete();public void FileDel(String filename) {// String fileName = "/sdcard/myImage/111.jpg";
//  Log.i("aaa", filename+" filename");String sdStatus = Environment.getExternalStorageState();if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { // 检测sd是否可用
//            Log.i("aaa",
//                    "SD card is not avaiable/writeable right now.");return;}File file = new File(filename);Log.i("aaa", file.delete()+" file.delete() "+filename);file.delete();}public byte[] getBitmapByte(Bitmap bitmap) {ByteArrayOutputStream out = new ByteArrayOutputStream();bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);try {out.flush();out.close();} catch (IOException e) {e.printStackTrace();}
//  for(int i=0;i<out.toByteArray().length;i++){
//   Log.d("liang", Integer.toBinaryString(out.toByteArray()[i])+" out.toByteArray()");
//  }return out.toByteArray();}public void FileSave1(byte[] b2){String sdStatus = Environment.getExternalStorageState();if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { // 检测sd是否可用
//          Log.i("aaa",
//                  "SD card is not avaiable/writeable right now.");return;}File file = new File("/sdcard/222/");if (!file.exists()) {file.mkdirs();// 创建文件夹}else{Log.i("aaa","sd");}FileOutputStream b;try {b = new FileOutputStream("/sdcard/222/m.m");//存储地址及文件名b.write(b2);//图片b.flush();b.close();} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}
}

转载于:https://my.oschina.net/u/1994482/blog/413168

ShowAllPic--图片相关推荐

  1. Python+OpenCV 图像处理系列(1)— Ubuntu OpenCV安装、图片加载、显示和保存

    Ubuntu 16.04 下安装 Opencv sudo apt-get install libopencv-dev sudo apt-get install python-opencv 或者使用 p ...

  2. FastAI 课程学习笔记 lesson 1:宠物图片分类

    文章目录 代码解析 神奇的"%" 导入fastAI 库 下载解压数据集 untar_data 获取帮助文档 help() ? ?? doc 设置路径 get_image_files ...

  3. 1 用python进行OpenCV实战之用OpenCV3实现图片载入、显示和储存

    code 将下面文档存为load_display_save.py #-*- coding:utf-8 -*- from __future__ import print_function #1 impo ...

  4. java 16进制与图片互转

    十六进制转成图片 /*** 十六进制转成图片* @author Administrator**/public static void saveToImgFile(String src,String o ...

  5. ttf,woff2字体转化为png图片,python读取图片

    20210326 乱码转换的时候 是同一套unicode编码 但是在不同的字体库中对应的字不同 20210324 https://jingyan.baidu.com/article/e73e26c0c ...

  6. LeetCode简单题之图片平滑器

    题目 包含整数的二维矩阵 M 表示一个图片的灰度.你需要设计一个平滑器来让每一个单元的灰度成为平均灰度 (向下舍入) ,平均灰度的计算是周围的8个单元和它本身的值求平均,如果周围的单元格不足八个,则尽 ...

  7. Typora+PicGo图床配置(本地图片-->网络url~博客必备)

    前段时间搭了一个hexo博客,但是发现了一个很大的问题,在Typora里编辑你的博文的时候,插入的图片都是一些本地图片,然后部署的时候根本不能加载这些图片~~ 其中一个解决方法就是通过一些平台,像知乎 ...

  8. OFRecord 图片文件制数据集

    OFRecord 图片文件制数据集 在 OFRecord 数据格式 和 加载与准备 OFRecord 数据集 中,分别学习了 OFRecord 数据格式,以及如何将其它数据集转为 OFRecord 数 ...

  9. CVPR2020论文解读:CNN合成的图片鉴别

    CVPR2020论文解读:CNN合成的图片鉴别 <CNN-generated images are surprisingly easy to spot- for now> 论文链接:htt ...

  10. php将图片链接转换为base64编码文件流

    /** * 图片链接转换为 base64 文件流 * @param $imgUrl * @return string */ function img_url_to_base64($imgUrl) {$ ...

最新文章

  1. 数据系列:如何在Windows Azure虚拟机上设置SQL Server
  2. linux 如何查看tomcat实时的日志
  3. ES6与canvas实现鼠标小球跟随效果
  4. 超日债违约引发大宗商品暴跌 伦铜大跌近9%
  5. mac命令行安装htop
  6. Linux有关Shell中if用法笔记
  7. 前端开发必看 | Vue在前端市场这么火,它到底是什么?
  8. IS-IS详解(六)——IS-IS LSP机制详解
  9. PostGis路径分析
  10. 把swf反编译成fla的几种方法
  11. 本特利330906-02-12-05-02-CN传感器
  12. 中仪股份管道机器人_中仪股份 X5-HT 管道CCTV检测机器人
  13. Java 强制删除文件或目录
  14. MySQL实验7存储过程_mySQL 教程 第7章 存储过程和函数
  15. java 大小写转换函数_java字符串大小写转换的两种方法
  16. TYUT太原理工大学2022需求工程考试填空题
  17. c# 中崎_C#版OPOS打印(基于北洋OPOS SDK二次开发包,支持EPSON和北洋、佳博、商祺等支持标准ESC/POS指令的POS打印机) | 学步园...
  18. viso 画背景框_officevisio怎么设置背景图和图纸...
  19. POJ 1392 Ouroboros Snake 欧拉回路
  20. 没有比这个更详细的Elasticsearch教程

热门文章

  1. [转]numpy性能优化
  2. Codeforces 697C Lorenzo Von Matterhorn(严格二叉树的LCA) - xgtao -
  3. WPF控件textBox多行输入设置
  4. Oracle database server 安装tips
  5. 微信的充值页面为啥长这样?(多图)
  6. 设计需要冲击力:「不怕没品味的人,就怕没品味的人用心」
  7. 离职后才搞懂vue项目开发流程中的疑惑点
  8. windows10 下Python3.5.4安装
  9. 【收藏】一篇快速帮企业转型区块链的锦囊
  10. 域与活动目录(下) windows server 2008