我正在开发一个应用程序,它从图库中选择一张图片,然后将该图片设置为壁纸。但这里的问题是只有部分图像设置为墙纸而不是整个图像,但我想将整个图像设置为墙纸。你能告诉我怎么做吗???
这是我的代码...
public class Scaleimage extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String FileName;
File file = new File("/sdcard/pictures");
File[] imageFiles = file.listFiles( );
if(imageFiles.length > 0 ) {
FileName = imageFiles[0].getName();
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(getBaseContext());
Bitmap myBitmap = BitmapFactory.decodeFile("/sdcard/pictures" + "/" + FileName);
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels << 1;
myBitmap = Bitmap.createScaledBitmap(myBitmap,width, height, true);
try {
wallpaperManager.setBitmap( myBitmap);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}