Я пытаюсь преобразовать scrollView
в jpg при нажатии ImageView
. Он преобразует только видимый вид, а не весь контент. Если я вручную установлю значение 2500 для totalHeight
без изменений, это даст только текущий вид с черным цветом для дополнительного размера.
shareEstimation.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ScrollView structureEstimation = findViewById(R.id.structure_estimate);
View u = StructureResult.this.findViewById(R.id.structure_estimate);
int totalWidth = structureEstimation.getChildAt(0).getWidth();
int totalHeight = structureEstimation.getChildAt(0).getHeight();
Bitmap b = getBitmapFromView(u, totalHeight, totalWidth);
//Bitmap b = getBitmapFromView(u, 2500, totalWidth);
String root = getFilesDir().toString();
String fname = "Estimation.jpg";
File file = new File(root, fname);
try {
FileOutputStream out = new FileOutputStream(file);
b.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
//MediaStore.Images.Media.insertImage(mContext.getContentResolver(), b, "Screen", "screen");
} catch (Exception e) {
e.printStackTrace();
}
//Toast.makeText(getApplicationContext(), file.toString(), Toast.LENGTH_LONG).show();
Intent i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(FileProvider.getUriForFile(getApplicationContext(), AUTHORITY, file), "image/*");
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
i.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getApplicationContext(), AUTHORITY, file));
startActivity(Intent.createChooser(i, "Share via"));
}
});
А это мой макет
<RelativeLayout>
<ScrollView>
<LinearLayout/>
</ScrollView>
</RelativeLayout>