2012-06-28 4 views
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(); 
} 

マイスクリーンオリジナル画像
enter image description here

マイスクリーンショットAndroidのエミュレータホーム画面
enter image description here

です。
My Original Imageの表示方法は、Emulator Sizeに基づいています。

+2

「私の画像のピクセルが完全に壊れていますか?」とはどういう意味ですか?どのようなコードを書いていますか?何を試しましたか? – bouteillebleu

+0

スクリーンショットを追加しないと、問題の原因がわかります。 – mariomario

+0

@mariomarioスクリーンショットが追加されました。 – Sekar

答えて

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

このコードは非常に機能しています。イメージサイズが '72 * 72'や' 1200 * 1200'でエミュレータのサイズが '480 * 480'ならば、結果は期待しています。ですから、ピクセルを壊さずに壁紙に設定して、イメージサイズを '480 * 480'に変更する必要があります。ありがとう。 – Sekar

+0

これはあなたが受け入れている答えであれば、この男に彼の恩恵を与える! – bkbeachlabs

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

これは私が私のイメージは全体で実行しているクレイジーラインせずにうまくスケールにするために使用するものです - あなたが壁紙のためにこれを試みることができる - それが動作するかどうかわからない、聞かせて私は知っている。

関連する問題