Android縦画面撮影90度
第一歩:AndroidManifest.xml Activityに次の属性を追加
?
?
2つ目は、縦画面で写真を撮った後に画像を保存すると90度回転するという問題を解決します.ここでは曲線で国を救うだけで、撮った画像をコードで90度回転させることです.
まず、現在は横撮りか縦撮りかを判断し、カメラを呼び出して撮影した後、画像を保存する方法で縦撮りの写真を90度回転させる.
?
?
<span>android:configChanges=
"orientation|keyboardHidden|screenSize"
android:screenOrientation=
"sensor"
, onCreate , onConfigurationChanged 。screenSize
4.0
, 。</span>
?
<application android:label=
"@string/app_name"
android:icon=
"@drawable/ic_launcher"
>
<activity android:name=
".MainActivity"
android:label=
"@string/app_name"
<span style=
"color: #ff0000;"
>android:configChanges=
"orientation|keyboardHidden|screenSize"
android:screenOrientation=
"sensor"
</span>>
<intent-filter>
<action android:name=
"android.intent.action.MAIN"
/>
<category android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
2つ目は、縦画面で写真を撮った後に画像を保存すると90度回転するという問題を解決します.ここでは曲線で国を救うだけで、撮った画像をコードで90度回転させることです.
まず、現在は横撮りか縦撮りかを判断し、カメラを呼び出して撮影した後、画像を保存する方法で縦撮りの写真を90度回転させる.
?
PictureCallback jpeg =
new
PictureCallback() {
@Override
public
void
onPictureTaken(
byte
[] data, Camera camera) {
// TODO Auto-generated method stub
Bitmap bMap;
try
{
//
bMap = BitmapFactory.decodeByteArray(data,
0
, data.length);
Bitmap bMapRotate;
Configuration config = getResources().getConfiguration();
if (config.orientation==1)
{ //
Matrix matrix = new Matrix();
matrix.reset();
matrix.postRotate(270);
bMapRotate = Bitmap.createBitmap(bMap, 0, 0,
bMap.getWidth(), bMap.getHeight(),
matrix, true);
bMap = bMapRotate;
}
// Bitmap bm = BitmapFactory.decodeByteArray(data, 0, data.length);
File file =
new
File(filePath);
BufferedOutputStream bos =
new
BufferedOutputStream(
new
FileOutputStream(file));
bMap.compress(Bitmap.CompressFormat.JPEG,
100
, bos);
//
bos.flush();
//
bos.close();
//
}
catch
(Exception e)
{
e.printStackTrace();
}
}
};
キーコードは です.
りで りするか、 りで りするかは、surfaceChangedメソッドでカメラのプレビューを し、カメラを すると90 しません.