try {
if (Environment.MEDIA_MOUNTED.equals(Environment
.getExternalStorageState())
&& Environment.getExternalStorageDirectory().exists()) {
TEST_IMAGE = Environment.getExternalStorageDirectory()
.getAbsolutePath() + FILE_NAME;
} else {
TEST_IMAGE = getApplication().getFilesDir().getAbsolutePath()
+ FILE_NAME;
}
// 创建图片文件夹
File file = new File(TEST_IMAGE);
if (!file.exists()) {
file.createNewFile();
Bitmap pic = BitmapFactory.decodeResource(getResources(),
R.drawable.gift);
FileOutputStream fos = new FileOutputStream(file);
pic.compress(CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
}
} catch (Throwable t) {
t.printStackTrace();
TEST_IMAGE = null;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
byte[] buffer = out.toByteArray();