捕捉整个滚动视图比屏幕越做越 [英] Capture whole scrollview bigger than screen

查看:179
本文介绍了捕捉整个滚动视图比屏幕越做越的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主要的问题是节省整个滚动视图作为位图图像,而不是在屏幕上只显示的内容。有没有一种方法,以节省整个滚动视图,如果又如何?

The main issue is saving the whole scroll view as a bitmap image rather than just what appears on the screen. Is there a way to save whole scroll view, and if so how?

推荐答案

制作的RelativeLayout或LinearLayout中在滚动型从布局得到位图。

Make a RelativeLayout or LinearLayout in your ScrollView to get Bitmap from Layout.

整理是这样的:

public class ActivityA extends Activity {

LinearLayout PP_Ll;
Button btn_capture;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.main);

PP_Ll = (RelativeLayout) findViewById(R.id.PP_Ll);
Button btn_capture= (Button) findViewById(R.id.btn_capture);

btn_capture.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

        Bitmap bitmap = takeScreenshot();
        saveBitmap(bitmap);

        }
    });

public Bitmap takeScreenshot() {

    View rootView = getWindow().getDecorView().findViewById(R.id.PP_Ll);
    rootView.setDrawingCacheEnabled(true);
    return rootView.getDrawingCache();

}

public void saveBitmap(Bitmap bitmap) {

    String root = Environment.getExternalStorageDirectory().toString();
    File newDir = new File(root + "/Folder");
    newDir.mkdirs();
    Random gen = new Random();
    int n = 10000;
    n = gen.nextInt(n);
    String fotoname = "Photo-" + n + ".jpg";
    File file = new File(newDir, fotoname);
    if (file.exists())
        file.delete();
    try {
        FileOutputStream fos = new FileOutputStream(file);
        bitmap.compress(CompressFormat.JPEG, 100, fos);
        fos.flush();
        fos.close();
        Toast.makeText(getApplicationContext(),
                "Saved in folder: 'Folder'", Toast.LENGTH_SHORT).show();

    } catch (FileNotFoundException e) {
        Log.e("GREC", e.getMessage(), e);
    } catch (IOException e) {
        Log.e("GREC", e.getMessage(), e);
    }

}
}}

您的RelativeLayout将保存在某个目录为位图。祝你好运。

Your RelativeLayout will be saved in certain directory as a BitMap. Good luck.

注意:您必须插入您的imageviews,textviews等入.xml文件的RelativeLayout的,所有可以进入的截图

Note: You have to insert your imageviews, textviews etc. into your RelativeLayout in .xml file that all can go into screenshot.

这篇关于捕捉整个滚动视图比屏幕越做越的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆