| | |
| | | package com.hdl.photovoltaic.utils; |
| | | |
| | | import android.content.Context; |
| | | import android.graphics.Bitmap; |
| | | import android.graphics.BitmapFactory; |
| | | import android.util.Log; |
| | | |
| | | import com.hdl.photovoltaic.other.HdlLogLogic; |
| | | |
| | | import java.io.BufferedInputStream; |
| | | import java.io.BufferedOutputStream; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileNotFoundException; |
| | |
| | | return fileContent; |
| | | } |
| | | FileInputStream fis = new FileInputStream(f); |
| | | byte[] bytes = new byte[(int) f.length()]; |
| | | byte[] bytes = new byte[fis.available()]; |
| | | fis.read(bytes); |
| | | fis.close(); |
| | | fileContent = new String(bytes, 0, bytes.length); |
| | | fileContent = new String(bytes); |
| | | return fileContent; |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 把位图数据保存到指定路径的图片文件 |
| | | */ |
| | | public static void writeImage(String path, Bitmap bitmap) { |
| | | try { |
| | | //根据指定文件路径构建缓存输出流对象 |
| | | BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(path)); |
| | | //把位图数据压缩到缓存输出流中 |
| | | bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos); |
| | | //完成缓存输出流的写入动作 |
| | | bos.flush(); |
| | | //关闭缓存输出流 |
| | | bos.close(); |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 从指定路径的图片文件中读取位图数据 |
| | | */ |
| | | public static Bitmap readImage(String path) { |
| | | try { |
| | | //根据指定文件路径构建缓存输入流对象 |
| | | BufferedInputStream bis = new BufferedInputStream(new FileInputStream(path)); |
| | | //从缓存输入流中解码位图数据 |
| | | Bitmap bitmap = BitmapFactory.decodeStream(bis); |
| | | //关闭缓存输入流 |
| | | bis.close(); |
| | | return bitmap; |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | } |
| | | |
| | | |