val imgBitmap = BitmapFactory.decodeByteArray(jdata, 0, jdata.size)
saveBitmapToSDCard(imgBitmap ,"sd path")
/**
* 转码处理
* @param data
* @param width 图片宽度
* @param height 图片高度
* @return
*/
private fun transcodeProcess(data: ByteArray, width: Int, height: Int): ByteArray {
val yuvImage = YuvImage(data, ImageFormat.NV21, width, height, null)
val baos = ByteArrayOutputStream()
yuvImage.compressToJpeg(Rect(0, 0, width, height), 80, baos)
return baos.toByteArray()
}
/**
* 将bitmap对象保存成图片到sd卡中
*/
public static void saveBitmapToSDCard(Bitmap bitmap, String path) {
try {
File file = new File(path);
if (file.exists()) {
file.delete();
} else {
new File(path.substring(0, path.lastIndexOf("/") + 1)).mkdirs();
}
FileOutputStream fileOutputStream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
fileOutputStream.close();
MLog.d("save success " + path);
} catch (Exception v0) {
v0.printStackTrace();
}
}
网友评论