gpt4 book ai didi

android - 如何将 ScrollView 中的所有内容转换为位图?

转载 作者:可可西里 更新时间:2023-11-01 18:49:59 26 4
gpt4 key购买 nike

我用下面的代码进行转换,但是好像只能获取显示屏幕上的内容,不能获取显示屏幕外的内容。

有没有办法让所有的内容都脱离滚动条?

Bitmap viewBitmap = Bitmap.createBitmap(mScrollView.getWidth(),mScrollView.getHeight(),Bitmap.Config.ARGB_8888);  
Canvas canvas = new Canvas(viewBitmap);
mScrollView.draw(canvas);

最佳答案

我们可以使用下面显示的代码将 scrollView 的所有内容转换为位图图像

private void takeScreenShot() 
{
View u = ((Activity) mContext).findViewById(R.id.scroll);

HorizontalScrollView z = (HorizontalScrollView) ((Activity) mContext).findViewById(R.id.scroll);
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(mContext.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;
}

关于android - 如何将 ScrollView 中的所有内容转换为位图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8738448/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com