我正在尝试捕获ScrollView
中的所有项目并将其另存为图像。
private void takeScreenShot()
{
ScrollView z = (ScrollView) findViewById(R.id.scroll_view);
int totalHeight = z.getChildAt(0).getHeight();
int totalWidth = z.getChildAt(0).getWidth();
Bitmap b = getBitmapFromView(u,totalHeight,totalWidth);
//Save bitmap
String extr = Environment.getExternalStorageDirectory()+"/Folder/";
String fileName = "report.jpg";
File myPath = new File(extr, fileName);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myPath);
b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
MediaStore.Images.Media.insertImage(getContentResolver(), b, "Screen", "screen");
}catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Bitmap getBitmapFromView(View view, int totalHeight, int totalWidth) {
Bitmap returnedBitmap = Bitmap.createBitmap(totalWidth,totalHeight , Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(returnedBitmap);
Drawable bgDrawable = view.getBackground();
if (bgDrawable != null)
bgDrawable.draw(canvas);
else
canvas.drawColor(Color.WHITE);
view.draw(canvas);
return returnedBitmap;
}
生成的图片为enter image description here
黑色区域应该有一些文字,但没有显示。
如果某人有可行的解决方案,我将不胜感激。
答案 0 :(得分:0)
// Please get user's password as hash in $password_hash and plain text password from user. Then use password_verify function (native function) to verify the password
if(password_verify($_POST['password'] , $password_hash)
{
// correct password
}
else
{
// wrong password
}
只需将ScrollView或其直接子视图传递给上述功能。
试试这个,让我知道。希望它会有所帮助!
答案 1 :(得分:0)
有时它会将背景设置为黑色,如果它没有设置为任何东西,并且在创建位图时它会在黑色背景上显示为黑色文本。
您可以通过在.XML文件中添加背景颜色来解决此问题。请务必为要捕获的视图和视图中的每个项目添加背景颜色。任何没有设置背景的东西都会显示黑色背景。