- public static byte[] imageToBytes(String path) throws IOException {
- InputStream inputStream = new FileInputStream(path);
- BufferedInputStream in = new BufferedInputStream(inputStream);
- ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
- byte[] temp = new byte[1024];
- int size = 0;
- while ((size = in.read(temp)) != -1) {
- out.write(temp, 0, size);
- }
- in.close();
- byte[] content = out.toByteArray();
- return content;
- }
//图片转字节码
public Bitmap stringtoBitmap(String string){
//将字符串转换成Bitmap类型
Bitmap bitmap=null;
try {
byte[]bitmapArray;
bitmapArray=Base64.decode(string, Base64.DEFAULT);
bitmap=BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
} catch (Exception e) {
e.printStackTrace();
}
//字节码转图片