相机捕获的图像不适合imageview android

时间:2019-07-02 04:48:17

标签: android imageview

在我的应用程序中,我使用相机和图库选项上传图像,但是当图像上传的图像带有白色边框时保存。我想这样保存图像而没有白色边框。

import pandas as pd
xlsxname = input('File: ')
datacols = pd.read_excel(xlsxname, low_memory=False)
cols = list(datacols)
lencols = len(cols)
countup = 0
while countup != lencols:
    colstemp = cols[countup]
    data = pd.read_excel(xlsxname,
                       low_memory=False,
                       usecols=[colstemp])
    colsname = f'{colstemp}.dat'
    data.to_excel(colsname, index=False, header=False)
    countup = countup + 1

this is how image uploaded with white border

3 个答案:

答案 0 :(得分:0)

更改以下代码

 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);

如果您不想设置特定的固定高度,则可以设置为自动换行内容

答案 1 :(得分:0)

更改此行:

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

对此:

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

答案 2 :(得分:0)

将imageView的属性指定为 scaleType:fitXY ;)

  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);**
相关问题