new Thread(new Runnable() {
@Override
public void run() {
while(true) {
View view = findViewById(R.id.rootView);
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bmp = view.getDrawingCache();
if (bmp == null) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
continue;
}
String fn = "image_test.png";
String path = OmegaApp.getInstance().getFilesDir().getAbsolutePath() + File.separator + fn;
BufferedOutputStream bos = null;
try {
bos = new BufferedOutputStream(new FileOutputStream(new File(path)));
//压缩保存到本地
bmp.compress(Bitmap.CompressFormat.PNG, 100, bos);
bos.flush();
bos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
break;
}
}
}).start();
将layout布局转成图片下载到本地
最新推荐文章于 2024-05-28 00:05:08 发布