Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android imageview存在问题_Android_Imageview - Fatal编程技术网

Android imageview存在问题

Android imageview存在问题,android,imageview,Android,Imageview,我有一个安卓应用程序,我使用安卓摄像头拍照,然后我查看照片,如果我喜欢,然后我将照片上传到网站 上传图片到网站我注意到手机上有一些像素是看不见的!!!在网站上,图片有一些在手机屏幕上看不到的额外细节 手机屏幕上的图片设置为imageview 这是活动的布局: <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center"

我有一个安卓应用程序,我使用安卓摄像头拍照,然后我查看照片,如果我喜欢,然后我将照片上传到网站

上传图片到网站我注意到手机上有一些像素是看不见的!!!在网站上,图片有一些在手机屏幕上看不到的额外细节

手机屏幕上的图片设置为imageview

这是活动的布局:

<ImageView  
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_gravity="center"
android:scaleType="centerCrop"
android:id="@+id/myPic"
/>


有关额外代码或其他详细信息,我在这里向您介绍。谢谢

如果您说网站上的图像比手机上的图像大,那么这是因为您的缩放类型设置为:

android:scaleType="centerCrop"
并且您的imageview绑定可能与图像不匹配(因此图像被裁剪)。尝试将这一行添加到imageview中,看看是否会有所不同

android:adjustViewBounds="true"
最后,将布局高度和宽度属性更改为:

layout_width="fill_parent"
layout_height="wrap_content"

如果在使用scaleType属性时图像大小超出ImageView的边界:

android:scaleType="centerCrop"
然后您的图像将被裁剪,只显示适合您的ImageView的内容。为了解决这个问题,这里有一个助手方法,您可以调用它将图像缩小到所需的大小。它可能需要在你的一端进行一些调整,以适应你的情况,但它应该是有帮助的。这是一个稍加修改的版本,位于:

公共静态位图解码文件(文件f,int maxSize){
如果(f==null)
返回null;
试一试{
//解码图像大小
BitmapFactory.Options o=新的BitmapFactory.Options();
o、 inJustDecodeBounds=true;
解码流(新的FileInputStream(f),null,o);
//找到正确的刻度值。它应该是2的幂。
内部宽度=o.向外宽度,高度=o.向外高度;
int标度=1;
while(true){

如果(width_tmp/2根据您问题下方的评论,这是由
android:scaleType=“centerCrop”
语句引起的。它隐藏了图像的边框,因为设备屏幕上显示的唯一部分是适合它的部分


NSJonas在本页中提供了有关如何使图像适合屏幕的更多详细信息。

听起来您想要scaleType
“centerInside”
而不是
“centerCrop”

您指的是什么样的额外详细信息?不会
android:scaleType=“centerCrop”
解释裁剪吗?@Shlublu有额外的细节!我已经编辑了我的question@entoniocenterCrop应该按照我的要求重新缩放整个图像,使其适合我的屏幕…但它不会…一旦上传,我注意到屏幕上的某些像素不适合visible@entonio是的,这有点像我所怀疑的:如果细节确实存在于t图像中不可见的部分是由于<代码>中心作物>代码>。如果它在图像的中间,这可能是由于移动屏幕上的图像分辨率太小而无法看到的。我添加了一个辅助方法来缩放图像,希望它对你有用。不,不。我应该删除这行吗?:android:scaleType=“centerCrop”?@NSjonas…你还没有告诉我…这行android:scaleType=“centerCrop”应该从我的xml文件中删除吗?它的父视图中有任何维度约束吗?我应该删除这行吗:android:scaleType=“centerCrop”?因为NSjonas没有回答!
layout_width="fill_parent"
layout_height="wrap_content"
android:scaleType="centerCrop"
public static Bitmap decodeFile(File f, int maxSize){
    if (f == null)
        return null;
    try {
        //Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(new FileInputStream(f),null,o);

        //Find the correct scale value. It should be the power of 2.
        int width_tmp=o.outWidth, height_tmp=o.outHeight;
        int scale=1;
        while(true){
            if(width_tmp/2<maxSize || height_tmp/2<maxSize)
                break;
            width_tmp/=2;
            height_tmp/=2;
            scale*=2;
        }

        //Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize=scale;
        return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
    } catch (FileNotFoundException e) {}
    return null;
}