位图到壁纸调整大小比例 setWallpaper
我想缩放壁纸集的位图但没有效果:|我有这个代码以及原始文件夹和数组中的所有 .jpg 文件,代码:
baton3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
InputStream tapeta = getResources().openRawResource(textureArrayWin[n]);
Bitmap bitmap = BitmapFactory.decodeStream(tapeta);
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
int oldwidth= bitmap.getWidth();
int oldheight= bitmap.getHeight();
float skalaszerokosci = ((float) oldwidth) / width;
float skalawysokosci = ((float)oldheight) / height;
Matrix macierz = new Matrix();
macierz.postScale(skalaszerokosci, skalawysokosci);
Bitmap zmieniona = Bitmap.createBitmap(bitmap, 0, 0,
width, height, macierz, true);
try
{
getApplicationContext().setWallpaper(zmieniona);
}
catch(IOException e)
{
e.printStackTrace();
}
}
});
I want to scale Bitmap for Wallpaper set but no effect:| I have this code and all .jpg files in raw folder and array, code:
baton3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
InputStream tapeta = getResources().openRawResource(textureArrayWin[n]);
Bitmap bitmap = BitmapFactory.decodeStream(tapeta);
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
int oldwidth= bitmap.getWidth();
int oldheight= bitmap.getHeight();
float skalaszerokosci = ((float) oldwidth) / width;
float skalawysokosci = ((float)oldheight) / height;
Matrix macierz = new Matrix();
macierz.postScale(skalaszerokosci, skalawysokosci);
Bitmap zmieniona = Bitmap.createBitmap(bitmap, 0, 0,
width, height, macierz, true);
try
{
getApplicationContext().setWallpaper(zmieniona);
}
catch(IOException e)
{
e.printStackTrace();
}
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加到清单
;
add to manifest
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>
<uses-permission android:name="android.permission.SET_WALLPAPER" />
代码如下:
另外,不要忘记将 SET_WALLPAPER 添加到您的 manifest.xml 中:
Here's the code:
Also, don't forget to add the SET_WALLPAPER to your manifest.xml: