我正在尝试调整从相机库中获取的图像的大小,以使 ImageView 适合另一个活动。我正在获取图像。我只需要知道如何调整它的大小以适应 ImageView。
image1.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), 0);
}
});
}
protected void putExtras(Bundle bundle) {
// TODO Auto-generated method stub
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 0) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
System.out.println("Image Path : " + selectedImagePath);
image1.setImageURI(selectedImageUri);
}}}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
我的 xml
<ImageView
android:id="@+id/image1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_margin="3dp"
android:layout_weight=".1"
android:background="@drawable/greenline" />