今天我女朋友把手机把一张手机背景照片原稿删了,又没有备份。这下我遭殃了 非要我把这张照片弄出来,弄不出来跪键盘。本人参考了网上各大神的经验做了个apk。希望能帮到像我一样的苦命孩子
android手机背景照片原件删除后 背景不会改变。当修改背景照片时才会更改。因为在设置背景时系统复制的原件的副本隐藏于手机中。
以下android代码 把背景图片保存在/sdcard/Boohee中(就在文件游览器中找到Boohee文件夹 里面保存了桌面图片)
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.Bitmap.CompressFormat;
import android.graphics.Canvas;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class FindImage extends Activity implements OnClickListener {
/** Called when the activity is first created. */
private Button Button_1;
private Drawable wallpaperDrawable;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initView();
initData();
}
public void initView() {
Button_1 = (Button) findViewById(R.id.button_1);
Button_1.setOnClickListener(this);
}
public void initData() {
// 获取壁纸管理器
final WallpaperManager wallpaperManager = WallpaperManager
.getInstance(this);
// 获取壁纸图片
wallpaperDrawable = wallpaperManager.getDrawable();
// 图片视图
final ImageView imageView = (ImageView) findViewById(R.id.Image_View_1);
// 绘制缓存
imageView.setDrawingCacheEnabled(true);
// 设置图片
imageView.setImageDrawable(wallpaperDrawable);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.button_1:
saveImage(drawableToBitmap(wallpaperDrawable));
break;
}
}
public static File saveImage(Bitmap bmp) {
File appDir = new File(Environment.getExternalStorageDirectory(),
"Boohee");
if (!appDir.exists()) {
appDir.mkdir();
}
String fileName = System.currentTimeMillis() + ".jpg";
File file = new File(appDir, fileName);
try {
FileOutputStream fos = new FileOutputStream(file);
bmp.compress(CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return file;
}
public static Bitmap drawableToBitmap(Drawable drawable) {
int width = drawable.getIntrinsicWidth();
int height = drawable.getIntrinsicHeight();
Bitmap bitmap = Bitmap.createBitmap(width, height, drawable
.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, width, height);
drawable.draw(canvas);
return bitmap;
}
}
xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="get"/>
<ImageView
android:id="@+id/Image_View_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/star1"
/>
</LinearLayout>
android应用 链接
http://pan.baidu.com/s/1pJG7LGn 拖到手机中安装即可