日時: 2016/11/07 13:41 名前: lightbox
bmp2.compress(Bitmap.CompressFormat.JPEG,90,jpg);
拡張子:
FileOutputStream jpg;
try {
// 保存場所で FileOutputStream を作成
jpg = new FileOutputStream(imagePath);
if ( portrait ) {
// 縦の場合、回転して保存する
Bitmap bmp1 = BitmapFactory.decodeByteArray (data, 0, data.length);
int width = bmp1.getWidth();
int height = bmp1.getHeight();
Matrix matrix = new Matrix();
matrix.postRotate (90);
Bitmap bmp2 = Bitmap.createBitmap (bmp1, 0, 0, width, height, matrix, true);
// ▲ ここまでで、bmp1 を 90 度回転した、bmp2 を取得しています
// Bitmap(bmp2) を FileOutputStream(jpg) でファイル保存
bmp2.compress(Bitmap.CompressFormat.JPEG,90,jpg);
}
else {
// ここは、byte[] を直接保存
jpg.write(data);
jpg.close();
}
// ギャラリーに反映
MediaScannerConnection.scanFile(
MainActivity.this,
new String[] { imagePath },
new String[] { "image/jpeg" },
null);
} catch (Exception e) {
e.printStackTrace();
}
参考
|