我的问题是在imageview上预览的图片无法完全设置为背景墙纸。它的一部分削减。 这是我的按钮
setasW.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mImage.buildDrawingCache();
Bitmap bmap = mImage.getDrawingCache();
float scaleWidth = ((float) width) / bmap .getWidth();
float scaleHeight = ((float) height) / bmap .getHeight();
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap scaledBitmap = Bitmap.createBitmap(bmap, 0, 0,bmap .getWidth(), bmap .getHeight(), matrix, true);;
System.out.println("scaledBitmap-------"+scaledBitmap);
WallpaperManager m=WallpaperManager.getInstance(getApplicationContext());
try {
m.setBitmap(scaledBitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
});
这里的mimage是imageview 宽度和高度是屏幕尺寸。
如何将完整图像设置为壁纸?
答案 0 :(得分:0)
你可以直接使用我做了必要的修改
setasW.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DisplayMetrics outMetrics=new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
int w=outMetrics.widthPixels;
int h=outMetrics.heightPixels;
Rect rectgle= new Rect();
Window window= getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
int StatusBarHeight= rectgle.top;
int contentViewTop=
window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int TitleBarHeight= contentViewTop - StatusBarHeight;
mImage.buildDrawingCache();
Bitmap bmap = mImage.getDrawingCache();
bmap =Bitmap.createScaledBitmap(bmap ,w,(h-TitleBarHeight), true);
System.out.println("scaledBitmap-------"+scaledBitmap);
WallpaperManager m=WallpaperManager.getInstance(getApplicationContext());
try {
m.setBitmap(scaledBitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
});