如何转换的滚动视图为位图的所有内容? [英] How to convert all content in a scrollview to a bitmap?
本文介绍了如何转换的滚动视图为位图的所有内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用低于code转换,但似乎只能得到在显示屏的内容并不能得到内容没有在显示屏幕。
有没有办法让所有的内容甚至开出滚动?
位图viewBitmap = Bitmap.createBitmap(mScrollView.getWidth(),mScrollView.getHeight(),Bitmap.Config.ARGB_8888);
帆布油画=新的Canvas(viewBitmap);
mScrollView.draw(画布);
解决方案
我们可以将滚动视图中的所有内容使用如下
在code转换为位图图像 私人无效takeScreenShot()
{
查看U =((活动)mContext).findViewById(R.id.scroll);
HorizontalScrollView Z =(HorizontalScrollView)((活动)mContext).findViewById(R.id.scroll);
INT totalHeight = z.getChildAt(0).getHeight();
INT totalWidth = z.getChildAt(0).getWidth();
位图B = getBitmapFromView(U,totalHeight,totalWidth);
//保存位图
字符串抽= Environment.getExternalStorageDirectory()+/文件夹/;
字符串文件名=report.jpg;
文件mypath中=新的文件(抽,文件名);
FileOutputStream中FOS = NULL;
尝试 {
FOS =新的FileOutputStream(mypath中);
b.com preSS(Bitmap.Com pressFormat.JPEG,100,FOS);
fos.flush();
fos.close();
MediaStore.Images.Media.insertImage(mContext.getContentResolver(),B,屏幕,屏幕);
}赶上(FileNotFoundException异常E){
// TODO自动生成的catch块
e.printStackTrace();
}赶上(例外五){
// TODO自动生成的catch块
e.printStackTrace();
}
}
公共位图getBitmapFromView(查看视图,诠释totalHeight,诠释totalWidth){
位图returnedBitmap = Bitmap.createBitmap(totalWidth,totalHeight,Bitmap.Config.ARGB_8888);
帆布油画=新的Canvas(returnedBitmap);
可绘制bgDrawable = view.getBackground();
如果(bgDrawable!= NULL)
bgDrawable.draw(画布);
其他
canvas.drawColor(Color.WHITE);
view.draw(画布);
返回returnedBitmap;
}
I use below code to convert, but it seems can only get the content in the display screen and can not get the content not in the display screen.
Is there a way to get all the content even out of scroll?
Bitmap viewBitmap = Bitmap.createBitmap(mScrollView.getWidth(),mScrollView.getHeight(),Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(viewBitmap);
mScrollView.draw(canvas);
解决方案
We can convert all the contents of a scrollView to a bitmap image using the code shown below
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;
}
这篇关于如何转换的滚动视图为位图的所有内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文