Захваченное камерой изображение не помещается в imageview Android - PullRequest
2 голосов
/ 02 июля 2019

В моем приложении я использую камеру и опцию галереи для загрузки изображения, но когда загруженное изображение сохраняется с белой рамкой. Я хочу сохранить изображение как таковое без белой рамки.

//Image Scroll
HorizontalScrollView imagescroll = new HorizontalScrollView(this);
    imagescroll.setId(Integer.parseInt(questions.idquestion.get(j) + 700))
LinearLayout.LayoutParams imagelayoutparam = new LinearLayout.LayoutParams(MATCH_PARENT,WRAP_CONTENT);
                            imagescroll.setLayoutParams(imagelayoutparam);

//Image layout
final LinearLayout imagelayout = new LinearLayout(this);
LinearLayout.LayoutParams imlay = new LinearLayout.LayoutParams(MATCH_PARENT, 500);
imlay.setMargins(100, 0, 0, 0);
imagelayout.setLayoutParams(imlay);
imagelayout.setBackgroundColor(Color.RED);
imagelayout.setOrientation(LinearLayout.HORIZONTAL);
imagelayout.setId(Integer.parseInt(questions.idquestion.get(j) + 1000));

//Adding existing images
for (int k = 0; k < images.size(); k++) {
    final ImageView image = new ImageView(this);
    image.setLayoutParams(new android.view.ViewGroup.LayoutParams(500, 500));
    image.setMaxHeight(500);
    image.setMaxWidth(500);
    image.setBackgroundColor(Color.WHITE);
    final int var=k;
    final String abcd;
    String efgh="data:image/jpeg;base64,";
    abcd=efgh.concat(images.get(k));
    String encim = images.get(k).replace("data:image/jpeg;base64,", "");
    Log.d("MMMMM1",abcd);
    byte[] decodedString = Base64.decode(encim, Base64.DEFAULT);
    final Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
    image.setImageBitmap(decodedByte);

this is how image uploaded with white border

Ответы [ 3 ]

0 голосов
/ 02 июля 2019

Измените эту строку:

image.setLayoutParams(new android.view.ViewGroup.LayoutParams(500, 500));

на эту:

image.setLayoutParams(new android.view.ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 500));
0 голосов
/ 02 июля 2019

указать свойство imageView как scaleType: fitXY и быть nice ;)

  final ImageView image = new ImageView(this);
                                        image.setLayoutParams(new android.view.ViewGroup.LayoutParams(500, 500));
                                        image.setMaxHeight(500);
                                        image.setMaxWidth(500);
                                        image.setBackgroundColor(Color.WHITE);
**image.setScaleType(ImageView.ScaleType.FIT_XY);**
0 голосов
/ 02 июля 2019

Измените следующий код

 final ImageView image = new ImageView(this);
                                image.setLayoutParams(new android.view.ViewGroup.LayoutParams(500, 500));
                                image.setMaxHeight(500);
                                image.setMaxWidth(500);
                                image.setBackgroundColor(Color.WHITE);

на

 final ImageView image = new ImageView(this);
                                image.setLayoutParams(new android.view.ViewGroup.LayoutParams(your int size, your int size));
                                image.setMaxHeight(your int size);
                                image.setMaxWidth(your int size);

Если вы не хотите устанавливать конкретную фиксированную высоту, чем вы можете установить в качестве содержимого переноса

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...