0

我的问题是在 imageview 上预览的图像无法完全设置为背景墙纸。它的一部分被削减了。这是我点击按钮

    setasW.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
              mImage.buildDrawingCache();
              Bitmap bmap = mImage.getDrawingCache();

              float scaleWidth = ((float) width) / bmap .getWidth();
            float scaleHeight = ((float) height) / bmap .getHeight();
            Matrix matrix = new Matrix();
            matrix.postScale(scaleWidth, scaleHeight);

              Bitmap scaledBitmap = Bitmap.createBitmap(bmap, 0, 0,bmap .getWidth(), bmap .getHeight(), matrix, true);;
              System.out.println("scaledBitmap-------"+scaledBitmap);
             WallpaperManager m=WallpaperManager.getInstance(getApplicationContext());
             try {
                m.setBitmap(scaledBitmap);
             } catch (IOException e) {
                e.printStackTrace();
             }
        }
     });

这里 mimage 是 imageview 宽度和高度是屏幕尺寸。

如何将完整图像设置为墙纸?

4

1 回答 1

0

你可以直接使用这个我做了必要的修改

     setasW.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

     DisplayMetrics outMetrics=new DisplayMetrics();
                            getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
                            int w=outMetrics.widthPixels;
                            int h=outMetrics.heightPixels;


Rect rectgle= new Rect();
Window window= getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
int StatusBarHeight= rectgle.top;
int contentViewTop= 
    window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int TitleBarHeight= contentViewTop - StatusBarHeight;



                      mImage.buildDrawingCache();
                      Bitmap bmap = mImage.getDrawingCache();

                      bmap =Bitmap.createScaledBitmap(bmap ,w,(h-TitleBarHeight), true);
                      System.out.println("scaledBitmap-------"+scaledBitmap);
                     WallpaperManager m=WallpaperManager.getInstance(getApplicationContext());
                     try {
                        m.setBitmap(scaledBitmap);
                     } catch (IOException e) {
                        e.printStackTrace();
                     }
                }
             });
于 2013-06-03T11:08:34.183 回答