private void createSignFile() {
ByteArrayOutputStream baos = null;
FileOutputStream fos = null;
String path = null;
File file = null;
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
simpleDateFormat.applyPattern("yyyy年MM月dd日 HH时mm分ss秒");
path = Environment.getExternalStorageDirectory() + File.separator + simpleDateFormat.format(System.currentTimeMillis()) + ".jpg";
file = new File(path);
fos = new FileOutputStream(file);
baos = new ByteArrayOutputStream();
//如果设置成Bitmap.compress(CompressFormat.JPEG, 100, fos) 图片的背景都是黑色的
mSignBitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] b = baos.toByteArray();
if (b != null) {
fos.write(b);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fos != null) {
fos.close();
}
if (baos != null) {
baos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void savePic(String fileName) throws IOException {
File file = new File("/sdcard/pictures/" + fileName + ".png");
file.createNewFile();
FileOutputStream fileOS = new FileOutputStream(file);
cacheBitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOS);//注意是PNG格式的。若设置为JPG格式,背景色会变黑
fileOS.flush();
fileOS.close();
}