【问题标题】:High resolution image not displaying in image view when view in full screen mode?在全屏模式下查看时,高分辨率图像不显示在图像视图中?
【发布时间】:2013-12-31 22:34:47
【问题描述】:

我在三星 tab2 中以全屏模式显示图像,但无论何时显示大图像,图像视图中都没有显示。

image_view.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background_repet_"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imgFullImage"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_margin="15dp"
      />

</LinearLayout>

FullImageActivity.java:-

    ImageView imgFullImage;

    String dispFilename;
    String fileUrl;
    Bitmap bitmap;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.image_view);

        imgFullImage = (ImageView)findViewById(R.id.imgFullImage);

        fileUrl = getIntent().getExtras().getString("fileurl");
        dispFilename=getIntent().getExtras().getString("dispFilename");

            imgFullImage.setScaleType(ScaleType.FIT_CENTER);

                bitmap=decodeSampledBitmapFromResource(fileUrl,
        getDeviceWidth(FullImageActivity.this),getDeviceHeight(FullImageActivity.this));

               Log.e("Fill Image Size in 
                 Bytes","====>"+bitmap.getByteCount());     
        Log.e("Bitmap width & height","===>"+bitmap.getWidth() +"x"+bitmap.getHeight());
                imgFullImage.setImageBitmap(bitmap);


    }

  public static int getDeviceWidth(Activity activity) {
        int deviceWidth = 0;

        Point size = new Point();
        WindowManager windowManager = activity.getWindowManager();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            windowManager.getDefaultDisplay().getSize(size);
            deviceWidth = size.x;
        } else {
            Display display = windowManager.getDefaultDisplay();
            deviceWidth = display.getWidth();
        }
        return deviceWidth;
    }

@SuppressLint("NewApi")
public static int getDeviceHeight(Activity activity) {
    int deviceHeight = 0;

    Point size = new Point();
    WindowManager windowManager = activity.getWindowManager();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        windowManager.getDefaultDisplay().getSize(size);
        deviceHeight = size.y;
    } else {
        Display display = windowManager.getDefaultDisplay();
        deviceHeight = display.getHeight();
    }
    return deviceHeight;
}

public static Bitmap decodeSampledBitmapFromResource(String pathName,
        int reqWidth, int reqHeight) {

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(pathName, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth,
            reqHeight);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeFile(pathName, options);
}

public static int calculateInSampleSize(BitmapFactory.Options options,
        int reqWidth, int reqHeight) {
    // Raw height and width of image
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    if (height > reqHeight || width > reqWidth) {

        final int halfHeight = height / 2;
        final int halfWidth = width / 2;

        // Calculate the largest inSampleSize value that is a power of 2 and
        // keeps both
        // height and width larger than the requested height and width.
        while ((halfHeight / inSampleSize) > reqHeight
                && (halfWidth / inSampleSize) > reqWidth) {
            inSampleSize *= 2;
        }
    }

    return inSampleSize;
}

日志:-

12-13 13:31:45.238: E/Fill Image Size in Bytes(24036): ====>15668224
12-13 13:31:45.238: E/Bitmap width & height(24036): ===>2288x1712

如果有人有想法请回复。

提前谢谢...

【问题讨论】:

  • 您是否得到任何日志,例如位图太大而无法显示?
  • 不,我没有收到任何错误消息。

标签: android imageview fullscreen mode high-resolution


【解决方案1】:
public static Bitmap decodeSampledBitmapFromResource(String pathName,
            int reqWidth, int reqHeight) {

        // First decode with inJustDecodeBounds=true to check dimensions
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(pathName, options);

        // Calculate inSampleSize
        options.inSampleSize = calculateInSampleSize(options, reqWidth,
                reqHeight);

        // Decode bitmap with inSampleSize set
        options.inJustDecodeBounds = false;
        return BitmapFactory.decodeFile(pathName, options);
    }

    public static int calculateInSampleSize(BitmapFactory.Options options,
            int reqWidth, int reqHeight) {
        // Raw height and width of image
        final int height = options.outHeight;
        final int width = options.outWidth;
        int inSampleSize = 1;

        if (height > reqHeight || width > reqWidth) {

            final int halfHeight = height / 2;
            final int halfWidth = width / 2;

            // Calculate the largest inSampleSize value that is a power of 2 and
            // keeps both
            // height and width larger than the requested height and width.
            while ((halfHeight / inSampleSize) > reqHeight
                    && (halfWidth / inSampleSize) > reqWidth) {
                inSampleSize *= 2;
            }
        }

        return inSampleSize;
    }

【讨论】:

  • 它在许多分辨率下都可以正常工作,但是如果我使用 1532x900、2048x1365 等分辨率的用户图像可以正常工作,而 2288x1722 则没有任何显示。而 700x464 则不显示平板电脑屏幕的大小,但仅相等以图像大小显示。
  • 看不到图片的分辨率是多少?
  • 如果图像分辨率为 2288x1722,则不显示任何内容。
  • 当我使用 3000*4800 分辨率的图像时,我的代码也可以正常工作..我检查过..请把你的代码放在这里..
  • 还有一个问题。如果我缩放图像,那么图像质量会受到影响。
【解决方案2】:
public static void setImagesNew(ImageView img, String pathName,
            Activity activity) {

        Bitmap bmp = decodeSampledBitmapFromResource(pathName,
                getDeviceWidth(activity), getDeviceHeight(activity));

        img.setImageBitmap(bmp);

        bmp = null;
        System.gc();
        Runtime.getRuntime().gc();

    }

使用此功能,图像大小将与您的设备高度宽度兼容.. 您的问题与图像有关吗? 所以这是最好的解决方案....

【讨论】:

  • decodeSampledBitmapFromResource() 函数不存在。是否在内置函数中。
  • 非常感谢。我在你的回答中发表了评论。你知道吗。我到底有什么问题。
【解决方案3】:
@SuppressLint("NewApi")
    public static int getDeviceWidth(Activity activity) {
        int deviceWidth = 0;

        Point size = new Point();
        WindowManager windowManager = activity.getWindowManager();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            windowManager.getDefaultDisplay().getSize(size);
            deviceWidth = size.x;
        } else {
            Display display = windowManager.getDefaultDisplay();
            deviceWidth = display.getWidth();
        }
        return deviceWidth;
    }

    @SuppressLint("NewApi")
    public static int getDeviceHeight(Activity activity) {
        int deviceHeight = 0;

        Point size = new Point();
        WindowManager windowManager = activity.getWindowManager();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            windowManager.getDefaultDisplay().getSize(size);
            deviceHeight = size.y;
        } else {
            Display display = windowManager.getDefaultDisplay();
            deviceHeight = display.getHeight();
        }
        return deviceHeight;
    }

您可以使用设备的高度和宽度..并在 imageview 中设置此图像..

ImageView image = new ImageView(viewHomeScreen);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.FILL_PARENT,
                FrameLayout.LayoutParams.FILL_PARENT);

        params.height = getDeviceHeight(activity);
        params.width = getDevicewidth(activity);
FrameLayout framelayout = new FrameLayout(viewHomeScreen);

        framelayout.addView(image, 0, params);

希望对你有用

【讨论】:

  • 感谢回复,但我的问题是大图显示问题。普通图显示全屏模式很好。
【解决方案4】:

改成这样:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/background_repet_" >

<ImageView android:id="@+id/imgFullImage"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:layout_margin="15dp"
    android:scaleType="fitCenter"/>

</LinearLayout>

【讨论】:

  • 感谢您的回复,如果图像尺寸
猜你喜欢
  • 2013-04-16
  • 1970-01-01
  • 2013-04-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-23
  • 2012-10-12
相关资源
最近更新 更多