我有一个捕获图像并将该图像放在图像视图中的活动。但是限制是我只需要将图像放置在纵向模式下,当我在横向模式下拍摄图像时这会失败。因为在横向模式下捕获图像后图像会旋转。为了避免这种情况,我使用了
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,
ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
我在清单文件中进行了更改,例如 android:screenOrientation="portrait" android:screenOrientation="reversePortrait"
但是上面的事情并没有解决问题,任何人都可以在这里帮助......
我的活动是,
public class MainActivity extends Activity {
ImageView img1;
Button but;
@Override
public void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img1=(ImageView) findViewById(R.id.imageView1);
but=(Button) findViewById(R.id.button1);
but.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
takephoto();
}
});
}
public void takephoto()
{
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri pictureUri = Uri.fromFile(new
File(Environment.getExternalStorageDirectory()+"/img1.jpg"));
camera.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);
this.startActivityForResult(camera, 1);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
Bitmap
test=BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()
+"/img1.jpg");
img1.setImageBitmap(test);
}
}
我的清单文件是,
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>