9

嗨,我正在编码设置主屏幕壁纸。它工作正常。但是我的图像像素完全损坏,然后我的壁纸不适合主屏幕的实际尺寸。我正在尝试锻炼不同大小的图像。不幸的是,它对我不起作用。如何解决它。

我的代码在这里

WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
Drawable drawable = getResources().getDrawable(R.drawable.newimage);
Bitmap wallpaper = ((BitmapDrawable) drawable).getBitmap();           
try 
{
    wallpaperManager.setBitmap(wallpaper);
} 
catch (IOException e) 
{
    e.printStackTrace();
}

我的截图原始图像
在此处输入图像描述

我的屏幕截图 Android 模拟器主屏幕
在此处输入图像描述

为什么我的原始图像在这里损坏。
如何My Original Image根据Emulator Size.

4

2 回答 2

7

你可以试试这个:

WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
Drawable drawable = getResources().getDrawable(R.drawable.newimage);
Bitmap wallpaper_source = ((BitmapDrawable) drawable).getBitmap();           
try {
    int w = wallpaperManager.getDesiredMinimumWidth();
    int h = wallpaperManager.getDesiredMinimumHeight();
    int x = (w-wallpaper_source.getWidth())/2;
    int y = (h-wallpaper_source.getHeight())/2;
    Bitmap wallpaper = Bitmap.createBitmap(w, h, Config.ARGB_8888);
    Canvas c = new Canvas(wallpaper);
    c.drawBitmap(wallpaper_source, x,y, null);
    wallpaperManager.setBitmap(wallpaper);
} 
catch (IOException e) 
{
    e.printStackTrace();
}
于 2012-09-24T11:18:00.273 回答
0
WallpaperManager wallpaperManager = WallpaperManager.getInstance(activity);
    BitmapFactory.Options myOptions = new BitmapFactory.Options();
    myOptions.inDither = true;
    myOptions.inScaled = false;
    myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
    myOptions.inDither = false;
    myOptions.inPurgeable = true;
    Bitmap preparedBitmap = BitmapFactory.decodeResource(activity
            .getApplication().getResources(), R.drawable.newimage, myOptions);
    try 
    {
        wallpaperManager.setBitmap(preparedBitmap);
    } 
    catch (IOException e) 
    {
        e.printStackTrace();
    }

这就是我用来使我的图像很好地缩放而不会出现疯狂线条的方法-您可以尝试将其用于墙纸-不确定它是否有效,请告诉我。

于 2012-09-24T11:28:45.283 回答