Мое приложение имеет функцию экспорта, которая экспортирует копию ScrollView.Scrollview (включая фоновое изображение) устанавливается программно, но когда я экспортирую его копию, фон выглядит черным.
Я вызываю две функции, takeScreenshot () и затем saveBitmap ()
Как включить фоновое изображение?
private android.graphics.Bitmap takeScreenshot(View scroll) {
ScrollView iv = findViewById(R.id.scroll);
Bitmap bitmap = Bitmap.createBitmap(
iv.getChildAt(0).getWidth(),
iv.getChildAt(0).getHeight(),
Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bitmap);
iv.getChildAt(0).draw(c);
return bitmap;
}
public void saveBitmap(Bitmap bitmap) {
String root = Environment.getExternalStorageDirectory().toString();
File newDir = new File(root+"/NPCdata");
boolean test = newDir.mkdirs();
if (test){
String photoname = myNPC.getNpcMap().get("Name");
assert photoname != null;
photoname.replaceAll("\\s+", "");
String fotoname = photoname+".jpg";
File file = new File(newDir, fotoname);
while (file.exists()){
fotoname = photoname+"a"+".jpg";
file = new File(newDir, fotoname);
}
try {
FileOutputStream fos = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, fos);
fos.flush();
fos.close();
Toast.makeText(getApplicationContext(),
"Saved in folder: 'NPCdata'", Toast.LENGTH_SHORT).show();
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}