【问题标题】:How to to fit the image size to device screen size without losing image quality?如何在不损失图像质量的情况下使图像尺寸适合设备屏幕尺寸?
【发布时间】:2014-06-30 19:24:07
【问题描述】:

嗨,我正在尝试在 android 中做一个壁纸应用程序。我无法将图像设置为设备屏幕尺寸。当我将其设置为墙纸时,图像也会失去其质量。我也尝试了一些 stackoverflow 的答案,但没有给我正确的结果。

这是我的代码:

            public void onClick(View arg0) {

            WallpaperManager myWallpaperManager= WallpaperManager.getInstance(getApplicationContext());

           DisplayMetrics metrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(metrics);
            // get the height and width of screen
            int height = metrics.heightPixels;
            int width = metrics.widthPixels;
            try {
                Bitmap bitmap=((BitmapDrawable)imgflag.getDrawable()).getBitmap();
                if(bitmap!=null)
                    myWallpaperManager.setBitmap(bitmap);
                myWallpaperManager.suggestDesiredDimensions(width, height);
                Toast.makeText(SingleItemView.this, "Wallpaper Set", Toast.LENGTH_SHORT).show();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


        }

我在这里做错了什么?

【问题讨论】:

    标签: java android


    【解决方案1】:

    我想您尝试将缩略图(缩放)图像设置到屏幕上。

    试试这个代码:

    Bitmap bitmap = BitmapFactoty.decodeFile(path); // or decodeResource, decodeStream, etc
        // depends on your source
    

    代替:

    Bitmap bitmap=((BitmapDrawable)imgflag.getDrawable()).getBitmap();
    

    此来源必须包含大位图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-28
      • 1970-01-01
      • 2015-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多