私は、ギャラリーから画像を選択し、インテントを使って画像をトリミングすることができるようにするコードを作成しようとしています(プロファイル画像用)。私の切り抜かれたイメージはなぜ少しですか?
すべてがうまくいき、画像を選択できます。カスタムダイアログにあるImageViewにクロップして表示できます。私のカスタムダイアログのImageViewは幅と高さにwrap_contentを設定してもほとんどないので、ユーザーは切り抜かれた画像をほとんど見ることができません。ここで
はスクリーンショットです:Little image
コード:
私のカスタムダイアログ(custom_dialog_pp.xml):私のMainActivityで
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/style_layout_rounded_white">
<TextView
android:id="@+id/useit_customdialog_pp_TV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:gravity="center"
android:text="@string/usethispic"
android:textSize="25sp"
android:textColor="@color/white"
android:background="@drawable/style_tv_toproundcorner"/>
<ImageView
android:contentDescription="@string/profilpic"
android:id="@+id/pp_customdialog_pp_IV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/cancel_customdialog_pp_BTN"
android:background="@drawable/style_button_primary"
android:text="@string/cancel"
/>
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/done_customdialog_pp_BTN"
android:background="@drawable/style_button_primary"
android:text="@string/done"
/>
</LinearLayout>
:
////////////////////
ChangeProfilPic.onClickListener {
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, 2);
}
////////////////////
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 4 && resultCode == RESULT_OK && data != null) {
Bundle extras = data.getExtras();
Bitmap selectedImage = extras.getParcelable("data");
android.support.v7.app.AlertDialog.Builder mBuilderLoading = new android.support.v7.app.AlertDialog.Builder(MainActivity.this);
View mViewLoading = getLayoutInflater().inflate(R.layout.custom_dialog_pp,null);
final ImageView pp_customdialog_pp_IV = mViewLoading.findViewById(R.id.pp_customdialog_pp_IV);
pp_customdialog_pp_IV.setImageBitmap(selectedImage);
mBuilderLoading.setView(mViewLoading);
final android.support.v7.app.AlertDialog dialogLoading = mBuilderLoading.create();
dialogLoading.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialogLoading.show();
} else if(requestCode == 2 && resultCode == RESULT_OK && data != null) {
ImageCropFunction(data.getData());
}
}
public void ImageCropFunction(Uri imguri) {
try {
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(imguri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", 128);
cropIntent.putExtra("outputY", 128);
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, 4);
} catch (ActivityNotFoundException ignored) {
}
Ps:スクロッキングオプションを維持したい
「outputX」と「outputY」は「128」です。 128x128に戻った画像はありますか?たぶんそれは問題です –
@ th3pat3lそれは私に128または1000または50000を置くと同じ結果を与えます。 –
私の答えは以下を見てください。これを行うと、その '128'をより高い数字に変更しなければなりません。 512x512のようなサイズを試してください –