Android,设置背景拉伸或放大但永远不会更正

时间:2013-08-26 09:51:07

标签: java android wallpaper

我目前一直在尝试使用我制作的Android壁纸应用来设置手机的背景。但是,每次按“设置背景”时,它都会拉伸图像。

以下是我正在使用的代码

btnSetWallpaper.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                WallpaperManager wManager;

                try {

                    //  Bitmap bitmap = ((BitmapDrawable)imageView1.getDrawable()).getBitmap();
                    wManager = WallpaperManager.getInstance(view.getContext().getApplicationContext());

                    Display display = getWindowManager().getDefaultDisplay();
                    Point size = new Point();
                    display.getSize(size);
                    int fullWidth = size.x;
                    int fullHeight = size.y;

                    //int fullWidth   = wManager.getDesiredMinimumWidth();
                    //int fullHeight  = wManager.getDesiredMinimumHeight();

                    Log.d("Debug", Integer.toString(fullWidth));
                    Log.d("Debug", Integer.toString(fullHeight));

                    Bitmap bitmapResized = Bitmap.createScaledBitmap(bmpWallpaper, fullWidth * 2, fullHeight, true);
                    wManager.setBitmap(bitmapResized);


                } catch (IOException e) {
                    e.printStackTrace();
                }

                Core.makeNotification(view.getContext(), "MyNotification", "Your wallpaper has been set, enjoy!");
                Core.makeAlert(view.getContext(), "Wallpaper set", "Your wallpaper has been set, enjoy!");

            }
        });

1 个答案:

答案 0 :(得分:1)

好吧,在bakriOnFire的评论之后,我搜索了他给我的链接,在将我的代码与我描述的代码结合起来后,我找到了解决方案!

 btnSetWallpaper.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                try {
                    WallpaperManager wManager = WallpaperManager.getInstance(view.getContext());

                    Display display = getWindowManager().getDefaultDisplay();
                    Point size = new Point();
                    display.getSize(size);
                    int fullWidth = size.x;
                    int fullHeight = size.y;

                    //int fullWidth   = wManager.getDesiredMinimumWidth();
                    //int fullHeight  = wManager.getDesiredMinimumHeight();

                    Log.d("Debug", Integer.toString(fullWidth));
                    Log.d("Debug", Integer.toString(fullHeight));


                    Bitmap bitmapResized = Bitmap.createScaledBitmap(bmpWallpaper, fullWidth, fullHeight, true);
                    wManager.suggestDesiredDimensions(bitmapResized.getWidth(), bitmapResized.getHeight());

                    wManager.setBitmap(bitmapResized);



                } catch (IOException e) {
                    e.printStackTrace();
                }

                Core.makeNotification(view.getContext(), "MCPaper", "Your wallpaper has been set, enjoy!");
                Core.makeAlert(view.getContext(), "Wallpaper set", "Your wallpaper has been set, enjoy!");

            }
        });

我真的希望将来很好地帮助别人,因为我花了很长时间才做到这一点。享受