我正在開發一個應用程序,從圖庫中選擇一個圖像,然後將該圖像設置爲壁紙。但這裏的問題是,只有圖像的一部分被設置爲壁紙而不是整個圖像,但我想要將整個圖像設置爲壁紙。你能告訴我如何做到這一點嗎?如何適合整個圖像在屏幕上作爲壁紙
這裏是我的代碼...
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();
}
}
}
你正在創建自己的壁紙應用程序,還是你使用股票壁紙? – XGouchet 2012-07-10 07:26:53