为什么我的主屏幕壁纸损坏了?

时间:2012-06-28 08:34:25

标签: android

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

我的代码在这里

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();
}

我的截图原始图像
enter image description here

我的屏幕截图Android模拟器主屏幕
enter image description here

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

2 个答案:

答案 0 :(得分: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();
}

答案 1 :(得分: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();
    }

这就是我用来使我的图像很好地扩展而没有疯狂的线条 - 你可以试试壁纸 - 不知道它是否有效,请告诉我。