2011-10-17 2 views
0

J'ai image 640 * 480 dans la carte SD et je veux le définir comme fond d'écran d'accueil. Comment puis-je faire cela avec une petite perte de qualité? Avec mon code Wallpaper n'a pas une bonne clarté. C'est mon code:Définir le fond d'écran dans Android

private void setWallpaper(String filePath) throws IOException{ 
    if(filePath!=null){ 
    // set options for decoding 
    final BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inScaled = false; 
    options.inPreferredConfig = Bitmap.Config.ARGB_8888; 
    options.inDither = false; 
    options.inJustDecodeBounds = true; 
    //get bitmap from filepath 
    Bitmap bitmap = BitmapFactory.decodeFile(filePath, options); 
    //get sizes of bitmap 
    int width = bitmap.getWidth(); 
    int height = bitmap.getHeight(); 
    //get sizes of screen and scale level 
    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); 
    int newWidth = display.getWidth()*2; 
    int newHeight = display.getHeight(); 
    float scaleWidth = ((float) newWidth)/width; 
    float scaleHeight = ((float) newHeight)/height; 
    //set matrix of the scaling 
    Matrix matrix = new Matrix(); 
    matrix.postScale(scaleWidth, scaleHeight); 
    //get new bitmap for wallpaper 
    Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, 
      width, height, matrix, true); 
    //set bitmap as wallpaper 
    WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); 
    wallpaperManager.clear(); 
    wallpaperManager.setBitmap(resizedBitmap); 
    } 
    } 

Répondre

0

Chaque fois que vous augmentez la taille, vous allez subir une perte de qualité. Quel écran de taille essayez-vous d'afficher cette image? Gardez à l'esprit les dimensions du fond d'écran Android sont la hauteur de l'écran par 2 fois la largeur de l'écran (par exemple 800x480 écran a besoin d'une image 800x960).

Ma recommandation serait d'avoir une image plus grande et de l'échelle vers le bas. La perte de qualité due au sous-échantillonnage est beaucoup moins perceptible que celle de la conversion ascendante. Vous pouvez, si l'espace n'est pas un problème, inclure plusieurs tailles de l'image pour différentes résolutions d'écran.

+0

com.coolaris.media upscaling image avec une bonne qualité et de clarté lorsque je mets cette image en fond d'écran. Mais je ne sais pas comment utiliser ce paquet dans mon programme. –

Questions connexes