android 获得墙纸
来源:互联网 发布:泉州广电网络 编辑:程序博客网 时间:2024/03/29 16:50
package com.sn.android.image;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.app.WallpaperManager;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class ImageDemoActivity extends Activity {
private Button myBtn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myBtn = (Button) findViewById(R.id.btn_001);
myBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WallpaperManager wallpaperManager = WallpaperManager
.getInstance(ImageDemoActivity.this);
Drawable d = wallpaperManager.getDrawable();
if (d != null) {
if (saveWP("shi", d)) {
Toast.makeText(ImageDemoActivity.this, "Save ok",
Toast.LENGTH_SHORT);
}
}
}
});
}
public boolean saveWP(String filename, Drawable drawble) {
try {
saveMyBitmap(filename, drawableToBitmap(drawble));
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
public static Bitmap drawableToBitmap(Drawable drawable) {
Bitmap bitmap = Bitmap.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
canvas.setBitmap(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
public static void saveMyBitmap(String bitName, Bitmap mBitmap) {
File f = new File("/sdcard/" + bitName + ".png");
try {
f.createNewFile();
} catch (IOException e) {
Log.e("vsc-sxz", "在保存图片时出错:" + e.toString());
}
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
try {
fOut.flush();
} catch (IOException e) {
e.printStackTrace();
}
try {
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
- android 获得墙纸
- android-修改默认墙纸
- android 墙纸修改
- android-修改默认墙纸
- Android照片墙纸实现
- Android原理之动态墙纸
- android转屏换墙纸的实现
- 谷歌暂停部分Android墙纸应用程序
- Android原理揭秘系列之动态墙纸
- Android安卓动态墙纸编程
- 将Android Activity背景设置为墙纸
- Android源码中添加Livewallpapers(动态墙纸)的支持
- Android:设置默认墙纸为自己Activity的背景
- Android中当前墙纸Wallpaper存放的位置
- Android MTK 锁屏图片和背景墙纸的修改
- [原]墙纸
- 键盘墙纸
- 设置墙纸
- Android 源码下载 编译 环境变量设置
- Linux Android CTS 测试说明
- C++ auto_ptr(转)
- 计算机内存分配
- Eclipse自动成doc(文档)以及 chm 格式帮助文件
- android 获得墙纸
- android 深入学习资料
- Android Handle Thread Message 小说明
- 告别ASP.NET操作EXCEL的烦恼(总结篇)
- C----Study
- linux C print
- java 反射
- 如何利用反射去访问一个私有的方法
- 一段有意思的代码