android udp真是垃圾啊还是我写得垃圾
展开全部
PC端:<pre t="code" l="java">/**
* 把照片转换成 base64 格式
* @param path 照片路径
* @return 转换后的二进制照片
*/
private String getImageStr(String path) {
String base64code = null;
FileInputStream fis = null;
ByteArrayOutputStream baos = null;
File file = new File(path);
if (file.exists()) {
try {
fis = new FileInputStream(path);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int count = 0;
try {
while ((count = fis.read(buffer)) >= 0) {
baos.write(buffer, 0, count);
}
base64code = new String(Base64.encode(baos.toByteArray(),Base64.DEFAULT));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
fis.close();
baos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return base64code;
} android端:<pre t="code" l="java">/**
* 将Base64编码转换为bitmap
* @param base64String base64字符串
* @return 转换后的bitmap
*/
private Bitmap base64ToBitmap(String base64String){
byte[] bytes = Base64.decode(base64String, Base64.DEFAULT);
Bitmap bitmap=BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
return bitmap;
}拿到bitmap,任意处理
* 把照片转换成 base64 格式
* @param path 照片路径
* @return 转换后的二进制照片
*/
private String getImageStr(String path) {
String base64code = null;
FileInputStream fis = null;
ByteArrayOutputStream baos = null;
File file = new File(path);
if (file.exists()) {
try {
fis = new FileInputStream(path);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int count = 0;
try {
while ((count = fis.read(buffer)) >= 0) {
baos.write(buffer, 0, count);
}
base64code = new String(Base64.encode(baos.toByteArray(),Base64.DEFAULT));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
fis.close();
baos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return base64code;
} android端:<pre t="code" l="java">/**
* 将Base64编码转换为bitmap
* @param base64String base64字符串
* @return 转换后的bitmap
*/
private Bitmap base64ToBitmap(String base64String){
byte[] bytes = Base64.decode(base64String, Base64.DEFAULT);
Bitmap bitmap=BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
return bitmap;
}拿到bitmap,任意处理
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询